con.Open();
string select = "SELECT * FROM WHERE username='" + this.textBox1.Text + "' AND pasword='" + this.textBox2.Text + "'";
SqlCommand cmd = new SqlCommand("SELECT * FROM[Table_2]", con);
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
if (textBox1.Text == (reader["username"].ToString()) && textBox2.Text == (reader["pasword"].ToString()))
{
this.Hide();
Form2 frm = new Form2();
frm.Show();
frm.Activate();
}
else
{
MessageBox.Show("gabim");
}
con.Close();
答案 0 :(得分:0)
在关闭连接之前,您缺少While循环中的结束括号。您在阅读时正在有效地关闭连接:
con.Open();
string select = "SELECT * FROM WHERE username='" + this.textBox1.Text + "' AND pasword='" + this.textBox2.Text + "'";
SqlCommand cmd = new SqlCommand("SELECT * FROM[Table_2]", con);
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
if (textBox1.Text == (reader["username"].ToString()) && textBox2.Text == (reader["pasword"].ToString()))
{
this.Hide();
Form2 frm = new Form2();
frm.Show();
frm.Activate();
}
else
{
MessageBox.Show("gabim");
}
}
con.Close();