ExecuteScalar vs ExecuteNonQuery when returning an identity value
Trying to figure out if it's best to use ExecuteScalar or ExecuteNonQuery if I want to return the identity column of a newly inserted row. I have read this question and I understand the differences there, but when looking over some code I wrote a few weeks ago (whilst heavily borrowing from this site) I found that in my inserts I was using ExecuteScalar , like so: public static int SaveTest(Test newTest) { var conn = DbConnect.Connection(); const string sqlString = "INSERT INTO dbo.Tests ( Tester , Premise ) " + " VALUES ( @tester , @premise ) " + "SET @newId = SCOPE_IDENTITY(); "; using (conn