存储过程DLL类的代码帮助

本文关键字:代码 帮助 DLL 存储过程 | 更新日期: 2023-09-27 17:52:13

我正在为存储过程制作DLL类。帮我改正一下……我的老板说我缺少返回的参数值,但我没有得到任何东西来纠正它…

public class transactionService
{
SqlConnection cs;

private void OpenConnection()
{
cs = new SqlConnection();
cs.ConnectionString = "Data Source=IRIS-CSG-174;Initial Catalog=library_system;Integrated Security=True";
cs.Open();
}
public membership_details calculatefine()
{
OpenConnection();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Exec member_fine_detail";
cmd.Parameters.Add(new SqlParameter("member_id", SqlDbType.Int));

membership_details myObjec = new membership_details();
cmd.ExecuteNonQuery();
SqlDataReader sdr = cmd.ExecuteReader();
myObjec.fine_per_day = 0;

return myObjec;

帮我纠正这个代码…我试图得到fne_per_day作为每member_id和此参考后添加到返回形式的项目,根据member_id fine_per_day计算…如标准member_id=5,membership_desc=silver, gold,platinum,fineperday=30或20or10

存储过程DLL类的代码帮助

我认为您将需要这样的东西来返回存储过程的out参数:

public membership_details calculatefine()
{
     OpenConnection();
     SqlCommand cmd = new SqlCommand();
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.CommandText = "Exec member_fine_detail";
     cmd.Parameters.Add(new SqlParameter("@member_id", SqlDbType.Int));
     //Sql parameter corresponding to the output parameter
     cmd.Parameters.Add(new SqlParameter("@fine_per_day", SqlDbType.Int));
     cmd.Parameters[cmd.Parameters.Count - 1].Direction = ParameterDirection.Output;
     //execute the stored procedure
     cmd.ExecuteNonQuery();
     //obtain the value for the output parameter
     myObjec.fine_per_day = (int)cmd.Parameters["@fine_per_day"].Value;
     return myObjec;
}