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);
    }


}
}​

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

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+"'"; 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.