title: MS Access - C# - Retrieve the latest inserted guid
body: <p>Is there a way to retrieve the latest inserted guid in access with C#?</p>
  
  <p>I tried this: Created a table Cars with a field Id of type autonumber, replicationID and a field Name varchar(250).</p>
  
  <pre><code>var command = myConnection.CreateCommand();
  command.Connection.Open();
  command.CommandText = "INSERT INTO Cars(Name) VALUES ('Pagani')";
  command.ExecuteNonQuery();
  command = context.Database.Connection.CreateCommand();
  command.CommandText = "SELECT @@Identity";
  Console.WriteLine(command.ExecuteScalar());
  command.Connection.Close();
  </code></pre>
  
  <p>The issue which I am getting is:</p>
  
  <pre><code>Console.WriteLine(command.ExecuteScalar());  
  </code></pre>
  
  <p>always shows <code>0</code></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>To create the table you can use this statement over the C# OleDb connection (I think that from MS Access query does not work)</p>
  
  <pre><code>CREATE TABLE [Cars] (
   [Id] guid not null DEFAULT GenGUID(),
   [Name] text null
  );
  ALTER TABLE [Cars] ADD CONSTRAINT [PK_Cars_6515ede4] PRIMARY KEY ([Id])
  </code></pre>