现在的位置: 首页 > 综合 > 正文

.NET现成程序给你用[五]

2013年08月04日 ⁄ 综合 ⁄ 共 920字 ⁄ 字号 评论关闭

后台登陆部分.

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();

    }
   }

抱歉!评论已关闭.