我有一个存储过程,该过程返回2个输出参数和一条记录。
但是在C#中:
ExecuteReader
不允许返回值,但允许记录ExecuteNonQuery
允许返回值,但不能记录。我怎样才能两者兼得?
在关闭DataReader之前,存储过程返回的输出参数不可用。
假设你有
SqlDataReader reader = cmd.ExecuteReader();
...... do you record reading
reader.Close();
// Now the output parameters are available
int result = (int)cmd.Parameters["OutputParameter1"].Value;
当然,这是假设您已正确设置输出参数。
在使用SqlDataReader时,关联的SqlConnection忙于为SqlDataReader提供服务,除了关闭SqlConnection之外,无法对SqlConnection进行任何其他操作。在调用SqlDataReader的Close方法之前,情况就是这样。例如,只有在调用“关闭”之后才能检索输出参数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句