cmd.Parameters.Add("@TotalRecords", SqlDbType.Int);
cmd.Parameters["@TotalRecords"].Direction = ParameterDirection.Output;
reader = cmd.ExecuteReader();
while (reader.Read())
{
//...
}
TotalRecords = Convert.ToInt32(cmd.Parameters["@TotalRecords"].Value);
DataReader对象是独占连接的,不关DataReader返回参数值取不出来的
所以在TotalRecords = Convert.ToInt32(cmd.Parameters["@TotalRecords"].Value);前必须先把reader关闭
cmd.Parameters.Add("@TotalRecords", SqlDbType.Int);
cmd.Parameters["@TotalRecords"].Direction = ParameterDirection.Output;
reader = cmd.ExecuteReader();
while (reader.Read())
{
//...
}
reader.Close();
TotalRecords = Convert.ToInt32(cmd.Parameters["@TotalRecords"].Value);