C# 返回值在业务逻辑层中不更改
我必须在我的应用程序中使用三层体系结构。我必须在我的业务访问层中获取数据访问层返回值,但我无法在我的业务访问层中获取不断变化的值 我的代码隐藏页 我的业务访问层:- 我的数据访问层:-C# 返回值在业务逻辑层中不更改,c#,asp.net,C#,Asp.net,我必须在我的应用程序中使用三层体系结构。我必须在我的业务访问层中获取数据访问层返回值,但我无法在我的业务访问层中获取不断变化的值 我的代码隐藏页 我的业务访问层:- 我的数据访问层:- 在这里,一切正常,但returncode参数值在我的业务层中没有改变。我不知道如何在我的业务访问层中获取returncode参数。您不会在任何地方获取/分配返回值。可能您正在寻找类似的内容 int Result = obj.empReg(txtUserName.Text, txtPassword.Text, is
在这里,一切正常,但returncode参数值在我的业务层中没有改变。我不知道如何在我的业务访问层中获取returncode参数。您不会在任何地方获取/分配返回值。可能您正在寻找类似的内容
int Result = obj.empReg(txtUserName.Text, txtPassword.Text, isactive, Convert.ToInt32(hdntest.Value));
可能您需要进行以下更改,不使用参数时不需要在参数中发送returncode 代码隐藏: 业务层: 数据访问层:
returncode参数在哪里?您正在从后面的代码调用obj.empReg,并且从该方法返回一个整数,而不使用它!?那么,为什么在不使用整数的情况下返回整数呢?在EmpRegistration方法中是否有任何异常?
public int empReg(string username, string password, int isactive, int returncode)
{
return obj.EmpRegistration(username, password, isactive, returncode);
}
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;
}
}
int Result = obj.empReg(txtUserName.Text, txtPassword.Text, isactive, Convert.ToInt32(hdntest.Value));
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; }
}