后台登陆部分.
private void Button1_Click(object sender, System.EventArgs e) { string UserName=Request.Form["sys_name"]; string Password=Request.Form["sys_password"]; if (UserName.ToString()=="") { Response.Write("<script>alert('用户名不能为空');</script>"); } else { if (Password.ToString()=="") { Response.Write("<script>alert('密码不能为空');</script>"); } else { SqlConnection myConn=DBCONN.CreateCon(); myConn.Open(); string SqlStr = "select * from sys_admin where sys_name='"+UserName+"' and sys_password='"+Password+"'"; SqlCommand StrCmd=new SqlCommand(SqlStr,myConn); SqlDataReader myRead=StrCmd.ExecuteReader(); if (myRead.Read()) { Session["UserName"]="UserName"; Response.Write("<script>location.href='Admin_Index.aspx';</script>"); } else { Response.Write("<script>alert('用户名或者密码错误,请重试');</script>"); } myRead.Close(); myConn.Close();
} } |