日期:2014-05-18  浏览次数:20495 次

asp中如何获取存储过程的返回值?
存储过程里有个return @count 是返回查询记录的条数
asp中:
 SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConStr"]);
  SqlCommand comm = new SqlCommand();
  comm.Connection = conn;
  comm.CommandText = "UserInfo_Select";
  comm.CommandType = CommandType.StoredProcedure;
  comm.Parameters.AddWithValue("@NickName", NickName);
  comm.Parameters.AddWithValue("@type", 0);
  conn.Open();
  int temp= comm.ExecuteNonQuery();
  ……
我要想获得存储过程里返回的记录条数 该怎么写呢?

------解决方案--------------------
冒泡接分

不就是temp么?
------解决方案--------------------
就是temp......
------解决方案--------------------
探讨
就是temp......

------解决方案--------------------
探讨
冒泡接分

不就是temp么?

------解决方案--------------------
是temp?? 确实是temp .ExecuteNonQuery()方法就是返回影响记录的条数.
就跟sql一样
------解决方案--------------------
好像command对象有个ReturnVal属性.
------解决方案--------------------
/// <summary>
/// 执行Oracle存储过程,
/// </summary>
/// <param name="procedureName">存储过程名称</param>
/// <param name="parameterColl">存储过程参数集合</param>
/// <param name="outField">返回参数</param>
/// <returns></returns>
public static string RunProcedure(string procedureName, OracleParameter[] parameterColl, string outField, OracleConnection conn)
{
string result = "";

try
{
InitDB();//打开数据库连接
OracleCommand cmd = new OracleCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = conn;
cmd.CommandText = procedureName;

foreach (OracleParameter para in parameterColl)
{
cmd.Parameters.Add(para);
}
if (cmd.Connection.State == ConnectionState.Closed)
cmd.Connection.Open();

cmd.ExecuteNonQuery();
cmd.Connection.Close();
result = cmd.Parameters[outField].Value.ToString();
}
catch (Exception ex)
{
BusinessLogical.Error.SystemLog.WriteLog("RunProcedure() " + ex.Message + " " + ex.Source);//写日志
}
return result;

}