【发布时间】:2014-08-05 05:54:03
【问题描述】:
我必须在我的应用程序中使用三层架构。我必须在业务访问层中获取数据访问层返回值,但我无法在业务访问层中获取不断变化的值。
我的代码隐藏页面
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);
}
我的数据访问层:-
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 参数。
【问题讨论】:
-
这里的returncode参数在哪里?
-
您正在从后面的代码中调用
obj.empReg(),并且您从该方法返回一个整数而不使用它!?那么为什么在不使用它的时候返回一个整数呢? -
您的
EmpRegistration方法是否有异常?