public static void CreateSocialGroup(string FBUID)
{
string query = \"INSERT INTO SocialGroup (created_by_fbuid) VALUES (@FBUID); SELECT @@IDENTITY AS LastID\";
Use Stored Procedure only for the queries and use SCOPE_IDENTITY to get max value.
OUTPUT clause?
string query = "INSERT INTO SocialGroup (created_by_fbuid)
OUTPUT INSERTED.IDCol --use real column here
VALUES (@FBUID)";
...
int lastId = (int)command.ExecuteScalar();
cmd = new SqlCommand("Insert into table values (1,2,3); SELECT SCOPE_IDENTITY()", conn);
lastRecord = cmd.ExecuteScalar().ToString();
I'd recommend to use a stored procedure to do this. You can give it an OUTPUT parameter which you can use to return the id value back to your app.
You can use ExecuteScalar to get the last value from a Sqlcommand.
The scope_identity() function is safer than @@identity.
U can try ExecuteScalar for getting the LastID value.