我的意思是用窗体设计了一个登录界面,登陆的账号密码我想是通过数据库验证账号密码是否正确。点击登录就跳转到主窗体。这个怎么弄?
界面
------解决方案--------------------
在登陆窗口中添加一个按钮,在这个按钮中添加下面的代码
//登入
int count = 0;
string connStr = "连接字符串,在你的程序中连接数据库时直接复制过来";
//1、写连接字符串,打开数据库的链接
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
//2、发送sql语句命令,并执行
SqlCommand com = new SqlCommand();
//com.CommandText = "select username,password from users where username='" + this.textBox1.Text + "'";
com.CommandText = "select * from student";
com.CommandType = CommandType.Text;
com.Connection = conn;
SqlDataReader dr = com.ExecuteReader();
//3、查询出来的数据进行遍历
while (dr.Read())
{
string username = dr.GetString(0).Replace(" ", "");
string password = dr.GetString(1).Replace(" ", "");
if (username.Equals(this.IDtextBox.Text) && password.Equals(this.PasswortextBox.Text))