2011-08-08 17 views
1

我正在使用vs 2008在asp.net c#中执行项目。我希望在3层体系结构中执行我的项目。我可以将值插入到表使用3tier.But无法登录到页面只有注册是可能的。在运行它显示错误为“程序或功能'登录'期望参数'@iusername',这是没有提供。”使用3层体系结构在asp.net中无法登录到页面c#

我的代码是下面

表示层

protected void submit_Click(object sender, EventArgs e) 
    { 

    String xusername = uname.Text; 

    String xpwd = pwd.Text; 

    try 
    { 
     bool match = oBAL.checking(xusername, xpwd); 

     if (match == true) 
     { 
      Session["Username"] = xusername; 
      Response.Redirect("page.aspx"); 
     } 

     else 
     { 
      ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Invalid UserName or Password');", true); 
     } 
    } 
    catch (Exception ee) 
    { 
     Label1.Text = ee.Message.ToString(); 

    } 
    finally 
    { 
     oBAL = null; 
    } 

} 

BusinessLayer给出

public bool checking(string susername, string spwd) 
{ 
    ownerDAL oDAL = new ownerDAL(); 
    bool match = false; 


    DataSet ds = oDAL.Logincheck(); 


    try 
    { 
     int noofrows = ds.Tables["Userstable"].Rows.Count; 
     for (int i = 0; i < noofrows; i++) 
     { 
      if ((ds.Tables["Userstable"].Rows[i]["username"].ToString() == susername) && (ds.Tables["Userstable"].Rows[i]["pwd"].ToString() == spwd)) 
      { 
       match = true; 
      } 
     } 
     return match; 


    } 
    catch 
    { 
     throw; 
    } 
    finally 
    { 
     oDAL = null; 
    } 
    } 
    } 

数据层

 public DataSet Logincheck() 
{ 
    SqlConnection con = new SqlConnection(str); 
    con.Open(); 
    SqlCommand cmd = new SqlCommand("login", con); 
    cmd.CommandType = CommandType.StoredProcedure; 
    SqlDataAdapter da=new SqlDataAdapter(cmd); 
    DataSet ds=new DataSet(); 
    try 
    { 

     da.Fill(ds, "Userstable"); 
     return ds; 
    } 
    catch 
    { 
     throw; 
    } 

    finally 
    { 
     cmd.Dispose(); 
     con.Close(); 
     con.Dispose(); 
    } 

} 

StoredProcedure的

   ALTER PROCEDURE dbo.login 

(
@iusername varchar(50), 
@ipwd varchar(50) 


) 

AS 
    BEGIN 


SELECT  username, pwd 
    FROM   register 
    WHERE  (username = @iusername) AND (pwd = @ipwd) 

END

表名:寄存器 字段: 用户名(的PrimaryKey) PWD

我认为这是一个简单的错误。但作为初学者我找不到它。请提出一个好的解决方案。

回答

0

你的程序接受两个参数username和password,但你没有提供它。 将您的DAL功能Logincheck()更改为接受两个参数,就像您在业务层的bool checking(string susername, string spwd)中那样。

然后修改Logincheck()传递参数为StoredProcedure .. 而且你不需要一遍额外的检查,对BAL(用户名和密码),你已经在做它在你的SP.your Logincheck()在DAL可以很好地返回true /假基于

2

要检查的比赛在业务内容层 所以你需要有完整的用户列表 一个DataSet,以便改变procedue这样

ALTER PROCEDURE dbo.login  

AS 
    BEGIN  

SELECT  username, pwd 
    FROM   register 

或者你也可以传递参数给亲凭据(来自DataLayer)

cmd.Parameters.Add(UserName); 
cmd.Parameters.Add(Password); 
+0

感谢您的建议。我做了您的建议。但仍显示错误为“程序或函数'登录'期望参数'@iusername',它没有提供。 – user793987

+0

你修改了哪一个 - 更改程序或传递参数? – Shebin

+0

我改变了程序。在给出断点时,它会尝试使用dll,然后尝试使用dl.fill(ds,“Userstable”); return ds; }执行da.Fill(ds,“usertable”);然后退出try。不返回 – user793987

0

您的存储过程需要两个参数来验证登录并且您没有提供它。将用户名和密码传递给您的Sp或将您更改为以下,它将在您检查bl中的用户名和密码时起作用。

ALTER PROCEDURE dbo.login 
AS 
    BEGIN 
    SELECT  username, pwd FROM   register 
    WHERE  (username = @iusername) AND (pwd = @ipwd) 
    end