三层架构调用带有输出参数的存储过程
三层架构调用带有输出参数的存储过程(asp.net)在DAL 和BLL层里该怎么写..

解决方案 »

  1.   

    在DAL这样写,存储过程输出什么参数你就用什么类型来接收,然后方法返回
          SqlCommand com = new SqlCommand(prco + ".usp_UpdateRoomType存储过程名字", con);
          con.Open();
          com.CommandType = CommandType.StoredProcedure;
    在BLL里面就return 示例名。方法名
      

  2.   

    DAL层:Class:  InfoDALpublic int Add(string title,string desc,out int state)
    {
        state = 0;
        string cmdText = "sp_test";
        SqlParameter[] parameters ={
    new SqlParameter("@p_title",SqlDbType.VarChar,50),
    new SqlParameter("@p_desc",SqlDbType.VarChar,100),
            new SqlParameter("@p_state",SqlDbType.Int)
        };
        parameters[0].value = title;
        parameters[1].value = desc;
        parameters[2].Direction = ParameterDirection.Output;    int returnValue = 0;
        int.TryParse(My.SQLHelper.ExecuteNonQuery(Config.SqlConnectionString, CommandType.StoredProcedure, cmdText, parameters).ToString(),out returnValue);    if(parameters[2].value != null)
        {
             state = int.Prase(parameters[2].value.ToString());
        }
        return returnValue;
    }
    BLL层:Class:  InfoBLLpublic int Add(string title,string desc,out int state)
    {
        InfoDAL dal = new InfoDAL();
        return dal.Add(title,desc,out state); 
    }