以下是代码
private void btn_Login_Click(object sender, EventArgs e)
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = " select * from Table1 where Username='" + txt_Username.Text + "' and Password= '" + txt_Password.Text + "'";
OleDbDataReader reader = command.ExecuteReader();
//System.Data.OleDb.OleDbException:“至少一个参数没有被指定值。”
int count = 0;
while (reader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Username and Password are correct");
connection.Close();
connection.Dispose();
this.Hide();
Form2 f2 = new Form2();
f2.ShowDialog();
}
else
{
if (count > 1)
{
MessageBox.Show("Duplicate Username and Password");
}
else
{
MessageBox.Show("Username and/or Password are NOT correct");
}
}
connection.Close();
}