C# 登录界面从数据库取用户名密码匹配结束后进入登录界面

private void button9_Click(object sender, EventArgs e)
        {
            string constr = "server=XB-20160802BVHL;database=Level_2;uid=sa;pwd=wly561561";//连接字符串里包含了数据库信息
            SqlConnection cnn = new SqlConnection(constr);//创建数据库连接
            cnn.Open();//打开连接
           
            string sql = "select * from 用户信息 where 用户名='" + textBox1.Text + "' and 密码 ='" + textBox2.Text + "'";
            SqlCommand cmd = new SqlCommand();  //SqlCommand表示对数据库要执行的操作命令。
            SqlDataAdapter da = new SqlDataAdapter(sql,cnn);
            DataSet ds = new DataSet();
            da.Fill(ds,"用户信息");
            DataTable dt = new DataTable();
            if (ds.Tables[0].Rows.Count > 0)
            {
                this.Hide();
            }
            else 
            {
                MessageBox.Show("用户名或者密码错误!");
                textBox1.Text = "";
                textBox2.Text = "";
            }
        }       
 
        private void button10_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

 

转载于:https://www.cnblogs.com/topmount/p/8463593.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值