有没有友友帮忙看看数据库连接的代码为啥不能运行呀,拷贝的代码改了半天还是不行😭
private void btn_SignIn_Click(object sender, EventArgs e)
{
String username, password;
username = textBox1.Text;
password = textBox2.Text;
String myconn = @"server=LAPTOP-KJVSEVE9;database=institutions;Trusted_Connection=SSPI";//数据库实例连接字符串
SqlConnection sqlConnection = new SqlConnection(myconn);//新建数据库连接实例
sqlConnection.Open();//打开数据库连接
String sql = "select username,password from 1yhxx where username=''" + username + "and password=" + password + "''";//SQL语句实现表数据的读取
SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.HasRows)//满足用户名与密码一致,进入下一个界面
{
Form1 form1 = new Form1();//比如用户界面
form1.Show();
//this.Hide();
}
else//如果登录失败,询问是否注册新用户
{
DialogResult dr = MessageBox.Show("是否注册新用户?", "登录失败", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dr == DialogResult.Yes)//打开注册界面
{
Sign_up form2 = new Sign_up();
form2.Show();
//this.Hide();
}
else
{
this.Show();
}
}
}