C# .NET - What is the difference between ExecuteScalar and ExecuteNonQuery while saving

Asked By Daniel on 11-Oct-12 04:10 AM
Hi I have seen that some use the code below while saving in the database:

public bool Save()
    {
       ProductId = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.GetConnection(), "SaveProduct", ProductId, ProductName)
       return true;    
    }


public bool Save()
    {
       
            SqlHelper.ExecuteNonQuery(SqlHelper.GetConnection(), "SaveProduct", ProductId, ProductName);
            return true;
    }

My question is what is the difference between both code,which is better to use than the other,when to use them.And please explain me the first one,I do not understand very well that code.The second one is ok I can understand.
Thanks!
Robbe Morris replied to Daniel on 11-Oct-12 10:25 AM
ExecuteScalar is expecting a single record to be returned from your stored procedure.  So, the procedure is apparently running a query right after its insert/update statement.

ExecuteNonQuery just executes the procedure but does look for or process a query result.
Daniel replied to Robbe Morris on 11-Oct-12 12:21 PM
thanks!