login.aspx.cs

来自「这是个我的图书管理网站,大家可以参考参考,愿意和大家讨论」· CS 代码 · 共 51 行

CS
51
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
//该源码下载自www.51aspx.com(51aspx.com)

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strconn = ConfigurationManager.AppSettings["dsn"];
        //连接本地计算机的LMS数据库
        SqlConnection cn = new SqlConnection(strconn);
        cn.Open();
        //构造SQL语句,该语句在Users表中检查用户名和密码是否正确
        string mysql = "select * from  yhxx where yonghuname='" + TextBox1.Text + "'and mima='" + TextBox2.Text + "'";
        //创建Command对象
        SqlCommand cm = new SqlCommand(mysql, cn);
        //执行ExecuteReader ()方法
        SqlDataReader dr = cm.ExecuteReader();
        if (dr.Read())
        {
            //保存当前用户名及用户权限
            Session["uid"] = dr["yonghuID"].ToString();
            Session["leibie"] = RadioButtonList1.SelectedItem.Text;
     
            Response.Redirect("main.aspx");
        }
        else
        {
            this.TextBox1.Text = "";
            this.TextBox2.Text = "";

        }
        //关闭连接
        cn.Close();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?