gpt4 book ai didi

asp.net - ASP.NET应用程序和SQL Server的页面登录时出错

转载 作者:行者123 更新时间:2023-12-03 08:26:16 25 4
gpt4 key购买 nike

{
public DataTable EmpLoginbyId()
{
SqlConnection con = new SqlConnection("server=(local);database=schoolsystem;integrated security=true");
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter("EmpLoginbyId", con);
cmd.CommandType = CommandType.StoredProcedure;
adp.Fill(dt);
return dt;
}
public void EmpLogin(string Email, String Password)
{

SqlConnection con = new SqlConnection("server=(local);database=schoolsystem;integrated security=true");
SqlCommand cmd = new SqlCommand("EmpLogin", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@passward", Password);



con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

protected void Button1_Click(对象发送者,EventArgs e)
{
        try
{
Session["UID"] = Lgn.EmpLogin(TxtUN.Text, TxtPW.Text);
int? UID = Convert.ToInt32(Session["UID"].ToString());
DataTable dt = new DataTable();
dt = Lgn.EmpLoginbyId(Convert.ToInt32(UID));
string Username = dt.Rows[0]["UserName"].ToString();
//string Username = dt.Rows[0]["UserName"].ToString();
Session["ETID"] = Convert.ToInt32(dt.Rows[0]["UserTypeID"].ToString());
if (Username == null)
{
Session["UserName"] = Username.ToString();

}
if (UID.HasValue)
{
Response.Redirect("Admin.aspx");
}


}
catch { }
}

这是我的类(class)代码,它给了我这个错误
错误1无法将类型'void'隐式转换为'object'
错误2方法'EmpLoginbyId'没有重载接受1个参数

最佳答案

出现第一个错误是因为EmpLogin返回void,并且您试图将其分配给无效的某个对象。因此,要么从函数返回一些值,要么删除对 session 对象的赋值。

第二个错误是有效的,因为EmpLoginById的签名中没有任何参数。因此,可以通过删除UID来修改签名或调用函数。

关于asp.net - ASP.NET应用程序和SQL Server的页面登录时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40567186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com