Hi,
I have created a login form that has adminid and password..
I use visual studio 2005,database access.
login form work smoothly when i enter the correct adminid and password but never display an error message if wrong data was entered or no data was entered.
I need a help on this.
Along with this i show my coding.
Hope somebody will help me..
:)
private void button1_Click(object sender, EventArgs e)
{
String admId = textBox1.Text;
String passw = textBox2.Text;
OleDbConnection conn = new OleDbConnection("provider = microsoft.jet.oledb.4.0;data source = dbStd.mdb;");
try
{
conn.Open();
}
catch(Exception db)
{
MessageBox.Show("Error accessing the database: " + db.Message);
}
OleDbCommand command = new OleDbCommand();
command.Connection = conn;
command.CommandText = "SELECT AdminId,Password FROM Admin WHERE AdminId ='"+admId+"'AND Password = '"+passw+"'";
OleDbDataReader datareader = command.ExecuteReader();
while (datareader.Read()== true)
{
string autAdmin = datareader.GetString(0);
string autPass = datareader.GetString(1);
if (admId == autAdmin && passw == autPass)
{
MessageBox.Show("Welcome!");
}
else if (admId == "" || passw == "")
{
MessageBox.Show("Try Again");
}
}
datareader.Close();
conn.Close();
}