业务逻辑层的返回值不变

本文关键字:返回值 业务 | 更新日期: 2023-09-27 18:08:34

我必须在我的应用程序中使用三层体系结构。我必须在我的业务访问层中获得数据访问层返回值,但我无法在我的业务访问层中获得变化的值。

My Code Behind page

  protected void btnRegister_Click(object sender, EventArgs e)
            {
                if (IsPostBack)
                {
                    obj.empReg(txtUserName.Text, txtPassword.Text, isactive, Convert.ToInt32(hdntest.Value));
                    Response.Redirect("~/Login.aspx");
                }                               
            }

我的业务访问层:-

 public int empReg(string username, string password, int isactive, int returncode)
        {
           return obj.EmpRegistration(username, password, isactive, returncode);
        }

My Data Access Layer:-

 public int EmpRegistration(string username, string password, int isactive, int returncode)
        {
            isactive = 1;
            string cs = ConfigurationManager.ConnectionStrings["EmployeeDB"].ConnectionString;
            using (SqlConnection connection = new SqlConnection(cs))
            {
                SqlCommand com = new SqlCommand("sp_RegisterationUser", connection);
                com.CommandType = CommandType.StoredProcedure;
                string encryptedpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "SHA1");
                SqlParameter paramusername = new SqlParameter("@Username", username);
                com.Parameters.Add(paramusername);
                SqlParameter parampassword = new SqlParameter("@Password", encryptedpassword);
                com.Parameters.Add(parampassword);
                SqlParameter paramisactive = new SqlParameter("@isactive", isactive);
                com.Parameters.Add(paramisactive);
                connection.Open();               
                returncode = (int)com.ExecuteScalar();
                return returncode;
            }
        }

这里一切都很好,但returncode参数值在我的业务层中没有改变。我不知道如何在我的业务访问层中获得returncode参数

业务逻辑层的返回值不变

您没有在任何地方获取/分配返回值。也许你正在寻找这样的东西,

int Result = obj.empReg(txtUserName.Text, txtPassword.Text, isactive, Convert.ToInt32(hdntest.Value));

您可能需要以下更改,当您不使用它时,不需要在参数中发送returncode

代码后面:

 protected void btnRegister_Click(object sender, EventArgs e)
 { 
     //...      
     int iReturnCode = obj.empReg(txtUserName.Text, txtPassword.Text, isactive);
     //if(iReturnCode > 0)
     Response.Redirect("~/Login.aspx");                                        
 }
业务层

:

 public int empReg(string username, string password, int isactive)
 {
       return obj.EmpRegistration(username, password, isactive);
 }

数据访问层:

public int EmpRegistration(string username, string password, int isactive)
{ 
   try
   {
     //...
     using (SqlConnection connection = new SqlConnection(cs))
     {
          //...            
          return Convert.ToInt32(com.ExecuteScalar());                
     }
   }
   catch{ return -1; }       
 }