I have this simple query for inserting a new row into the database:
insert into Employees (name, salary) values ('123', 100); SELECT SCOPE_IDENTITY() as last_id;
This query run fine and return the recently added id but when i run the query in c#, it always return null.
Here is my c# code:
public static void InsertEmployee()
{
string sql = @"insert into Employees (name, salary) values ('123', 100); SELECT SCOPE_IDENTITY() as last_id; ";
SqlCommand command = new SqlCommand(sql, GetConnection());
command.Connection.Open();
var id = command.ExecuteScalar();
command.Connection.Close();
}