我正在使用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
我认为这是一个简单的错误。但作为初学者我找不到它。请提出一个好的解决方案。
感谢您的建议。我做了您的建议。但仍显示错误为“程序或函数'登录'期望参数'@iusername',它没有提供。 – user793987
你修改了哪一个 - 更改程序或传递参数? – Shebin
我改变了程序。在给出断点时,它会尝试使用dll,然后尝试使用dl.fill(ds,“Userstable”); return ds; }执行da.Fill(ds,“usertable”);然后退出try。不返回 – user793987