C# &引用;用户名或密码不正确";-得到同样的信息
我试图建立一个登录页面。但是,它始终显示以下信息: 用户名或密码不正确 虽然我很确定我的用户名和密码是正确的C# &引用;用户名或密码不正确";-得到同样的信息,c#,ms-access,C#,Ms Access,我试图建立一个登录页面。但是,它始终显示以下信息: 用户名或密码不正确 虽然我很确定我的用户名和密码是正确的 private void button1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtbox_user.Text) || string.IsNullOrEmpty(txtbox_password.Text)) //txt_name.Text == String.IsNullOrEmpty
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtbox_user.Text) || string.IsNullOrEmpty(txtbox_password.Text))
//txt_name.Text == String.IsNullOrEmpty || txt_family.Text == String.IsNullOrEmpty || txt_username.Text == String.IsNullOrEmpty || txt_password.Text == String.IsNullOrEmpty || txt_repeat.Text == String.IsNullOrEmpty || txt_mail.Text == String.IsNullOrEmpty)
{
MessageBox.Show("Plesae insert your username and password");
}
else
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = " select * from Login where UserName =' " + txtbox_user.Text + " ' and PassWord = ' " + txtbox_password.Text + " ' ";
OleDbDataReader reader = command.ExecuteReader();
int count = 0;
while (reader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Welcome!");
LearnerForm F2 = new LearnerForm();
F2.Show();
}
if (count > 1)
{
MessageBox.Show("Duplicate username or Password");
}
else
{
MessageBox.Show("Username or Password is not correct");
}
connection.Close();
}
}
引号
“
后有一个额外的空格。删除它:
where UserName =' " + txtbox_user.Text + " ' and PassWord = ' " + txtbox_password.Text + " '
应该是:
where UserName ='" + txtbox_user.Text + "' and PassWord = '" + txtbox_password.Text + "'
此外,我强烈建议您始终使用以避免。谢谢@user2946329。它工作了,现在,我可以登录了,但它仍然显示“用户名或密码不正确”。@user3585203。。。您还应该正确地将
if
语句更改为else if
。将第二个if
更改为else if
。@user3585203:您的第二个if
应该是else if
。我们可以确保计数等于或小于1..,检查您的else语句并输出sql ecc以了解您在做什么。。。