title: SQL Server and C#: get last inserted id
body: <pre><code>public static void CreateSocialGroup(string FBUID)
  {
      string query = "INSERT INTO SocialGroup (created_by_fbuid) VALUES (@FBUID); SELECT @@IDENTITY AS LastID";
  
      using (SqlConnection connection = new SqlConnection(ConnectionString))
      {
          SqlCommand command = new SqlCommand(query, connection);
          command.Parameters.AddWithValue("@FBUID", FBUID);
  
          connection.Open();
          command.ExecuteNonQuery();
      }
  }
  </code></pre>
  
  <p>Is this the right way to do it? And how do i get LastID in to a variable? Thanks</p>