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

 

posted on 2018-02-23 21:46  topmount  阅读(597)  评论(0编辑  收藏  举报