You should be using
Convert.ToInt64(sqlComm.Parameters["@AddressID"].Value);
after you execute the command using ExceuteNonQuery
. For future reference, ExecuteScalar
returns the first column of the first row in the result set returned by the query. You're not returning anything, just setting the value of an OUTPUT
parameter.
Also you should DEFINITELY not swallow any SqlException
. Since your command and connection are already in using
blocks you don't need to add another try/catch/finally. Change it to to:
//try
//{
sqlComm.Connection.Open();
sqlComm.ExecuteNonQuery();
return Convert.ToInt64(sqlComm.Parameters["@AddressID"].Value);
// using Int64 since the SQL type is BigInt
//}
//catch (SqlException)
//{
//}
//finally
//{
// sqlComm.Connection.Close();
//}