ADO.NET Tips

1. SqlCommand.ExecuteScalar Method

  Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

2. SqlCommand.ExecuteNonQuery Method

  Executes a Transact-SQL statement against the connection and returns the number of rows affected.

3. 如果想拿到return value的值,可以在代码中新建一个ReturnValue类型的parameter, 但在数据库中不需要添加额外的parameter。具体如下

     SqlParameter parameter = new SqlParameter("@RETURN", SqlDbType.Int);
                parameter.Direction = ParameterDirection.ReturnValue;

原文地址:https://www.cnblogs.com/qijiage/p/3270729.html