Question : Get Key for record just inserted

Hi,
I am looking to take the key from a record just inserted. I will then execute a few more lines of code befor adding a new record to a different table of which one of the values will be the key from the previous table
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
SqlConnection con2 = new SqlConnection(connStr);
SqlCommand SQLCmd2 = new SqlCommand("SPAddKW", con2);
SQLCmd2.CommandType = System.Data.CommandType.StoredProcedure;
SQLCmd2.Parameters.AddWithValue("@AWGID", (row["AWGID"]));
SQLCmd2.Connection.Open();
SQLCmd2.ExecuteNonQuery();
// something like this to store the recently inserted key
// but this does not work
              int NewID;
              NewID = SQLCmd2.Execute("SELECT @@IDENTITY");

SQLCmd2.Connection.Dispose();

Answer : Get Key for record just inserted

Random Solutions  
 
programming4us programming4us