在winform 中调用存贮过程返回流水号id 运行出错!
#region 调用存贮过程返回流水号id
/// <summary>
/// 执行存储过程,返回影响的行数
/// </summary>
/// <param name="storedProcName">存储过程名</param>
/// <param name="parameters">存储过程参数</param>
/// <param name=" SerialNumber">流水号</param>字段 类型是int 自增长
/// /// <param name="feildName">feidName</param>
/// <returns></returns>
public static int RunProcedure(string storedProcName, IDataParameter[] parameters, string feidName, out int SerialNumber)
{
//using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlConnection connection = new SqlConnection(DatabaseConnetString1))
{
//int sn;
connection.Open();
SqlCommand command = BuildIntCommand(connection, storedProcName, parameters);
//SqlParameter sn = new SqlParameter("@SerialNumber", SqlDbType.Int);
//sn.Direction = ParameterDirection.Output;
//command.Parameters .Add(sn);
command.ExecuteNonQuery();
SerialNumber = (int)command.Parameters["feidName"].Value;
connection.Close();
return SerialNumber;
}
}
#endregion
------解决方案--------------------
是不是应该这样?报什么错?
SerialNumber = (int)command.Parameters["@feidName"].Value;
------解决方案--------------------
存储过程返回的自增变量是什么?[email protected],还是其他名字?
------解决方案--------------------
/// <summary>
2 /// 校验用户
3 /// </summary>
4 /// <param name="user">用户信息</param>
5 /// <returns></returns>
6 public static int VerifyUser(clsUser user)
7 {
8 int iRet;
9 string sql = String.Format("EXECUTE VerifyUser @myVerifyReader OUTPUT,'{0}','{1}'",user.username,user.password); //执行的T-SQL串
10 SqlCommand scmd = new SqlCommand(sql, conn);
11 scmd.Parameters.Add(new SqlParameter("@myVerifyReader",SqlDbType.Int));
12 scmd.Parameters["@myVerifyReader"].Direction = ParameterDirection.Output;
13 //
14
15 DBOpen(conn);
16 //在返回值上有问题
17 scmd.ExecuteNonQuery();
18 iRet = (int)scmd.Parameters["@myVerifyReader"].Value;
19 DBClose(conn);
20 return iRet;
21 }