0
public partial class Form4 : Form
{
    private OleDbConnection connect = new OleDbConnection();


    public Form4()
    {
        InitializeComponent();
        connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Bino Unity\Desktop\user1.accdb;Persist Security Info=False;";
    }

    private void Form4_Load(object sender, EventArgs e)
    {

    }

    private void login_button_Click(object sender, EventArgs e)
    {
        connect.Open();
        OleDbCommand command = new OleDbCommand();
        command.Connection = connect;
        command.CommandText =@"select * from log where User Name='"+textBox1.Text+"' and Password='"+textBox2.Text+"'";   
       OleDbDataReader reader =  command.ExecuteReader();
       int count = 0;
        while(reader.Read())
        {
            count = count+1;
        }
        if(count ==1)
        {
            MessageBox.Show("username and password is correct");
        }
        if(count >1)
        {
            MessageBox.Show("Duplicate username and password...Access Denied");
        }
        else
        {
            MessageBox.Show("username and password incorrect");
        }
        connect.Close();

        Form2 form = new Form2();
        form.ShowDialog(this);
    }


}
}‚Äč
3
Contributors
2
Replies
15
Views
2 Years
Discussion Span
Last Post by JerrimePatient
1

Hi

Your table is using field names with both spaces and potentially reserved words (password). So you will need to enclose both of these within square brackets (or rename the fields in the table).

command.CommandText = "select * from log where [User Name]='"+textBox1.Text+"' and [Password]='"+textBox2.Text+"'";

HTH

0

line 22:

command.CommandText =@"select * from log where User Name='"+textBox1.Text+"' and Password='"+textBox2.Text+"'"; 

change in to:

command.CommandText ="select * from log where [User Name]='"+textBox1.Text+"' and Password='"+textBox2.Text+"'"; 
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.