Here is a simple code
Try to call all data from the database where username=? and password=?
If the dataset returned is not null make him login else stop there with an error message
private void button1_Click(object sender, EventArgs e)
{
try
{
if (txtUsername.Text.Trim() == null || txtUsername.Text.Trim() == "")
{
MessageBox.Show("Enter an valid username");
txtUsername.Focus();
txtUsername.Text = "";
}
else if (txtPassword.Text.Trim() == null || txtPassword.Text.Trim() == "")
{
MessageBox.Show("Enter an valid password");
txtPassword.Focus();
txtPassword.Text = "";
}
else
{
OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
oleDbConnection1.Open();
OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("select * from masterusertable where userid='" + txtUsername.Text + "' AND passsword='" + txtPassword.Text + "'", oleDbConnection1);
oleDbCommand1.CommandType = CommandType.Text;
try
{
OleDbDataReader data = oleDbCommand1.ExecuteReader();
if (data.Read() == true)
{
this.Hide();
MainMenuForm mainmenuform = new MainMenuForm();
mainmenuform.Show();
}
else
{
MessageBox.Show("Enter an valid username or password");
txtUsername.Text = "";
}
}
catch (Exception exp)
{
MessageBox.Show("Exception at Database close any Access Database program and restart");
Console.WriteLine("Error", exp);
}
}
}
catch (Exception eps)
{
Console.WriteLine("Error",eps);
}
}