protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection objConnection = new SqlConnection(strConnet);
SqlCommand objCommand = new SqlCommand("", objConnection);
= "SELECT USERID,NICKNAME,USERROLE FROM USERS WHERE USERNAME=@NAME AND USERPASSWORD=@PASSWORD";
objCommand.Parameters.Add("NAME",SqlDbType.VarChar);
objCommand.Parameters.Add("PASSWORD", SqlDbType.VarChar);
objCommand.Parameters["NAME"].Value = tbxName.Text.Trim();
objCommand.Parameters["PASSWORD"].Value = tbxPassword.Text.Trim();
try
{
if (objConnection.State == ConnectionState.Closed)
{
objConnection.Open();
}
SqlDataReader result = objCommand.ExecuteReader();
if (result.Read() == true)
{
Session["USERID"] = result["USERID"].ToString();
Session["NICKNAME"] = result["NICKNAME"].ToString();
Session["USERROLE"] = result["USERRILE"].ToString();
if (Session["USERROLE"].ToString() == "1")
{
Response.Redirect("Manager.aspx");
}
else
{
Response.Redirect("Welcom.aspx");
}
}
else
{
labError.Visible = true;
}
}
上面是我写的一个登录模块的 垃圾代码
用的是SQL
仿照着写 access数据库大概就这个样子