I could use some help :( I am trying to get the last generated ID from an identity column in sql and assign it to a variable named ConvId The value has datatype int in sql server, I tried using int to get the value that didnt work and now i tried int32 because i found a conversion table that says that in c# it should be int32 that doesnt work either it keeps giving me this error. system.InvalidCastException below i pasted the code that generates the error please help if possible.
cmd = new SqlCommand();
cmd.CommandText = "SELECT SCOPE_IDENTITY()";
cmd.Connection = con;
Int32 ConvId = (Int32)cmd.ExecuteScalar();
Debug.Print("The last generated id value = " + ConvId);