Hi guys
i'm trying to just do a simple email/password validation on two text boxes.
This code runs but when i type in a correct email address it throws an error "Object reference not set to an instance of an object." on
AdAcc.InsertCommand.Connection = OleAcc;
I'm thinking i may need to link it to the database somehow.
And i don't want to use Try/Catch!!
Sorry if this is outrageously noobish.
public void tbemail_LostFocus(object sender, EventArgs e)
{
if ((tbemail.Text == "")||(tbemail.Text == "Email"))
{
tbemail.Text = "Email";
i = false;
}
else
{
String emQuery = "SELECT [Email] FROM Accounts where Email = "+tbemail.Text.ToString()+"";
if (emQuery == null)
{
i = false;
}
else
{
i = true;
}
}
}
public void button1_Click(object sender, EventArgs e)
{
OleDbConnection OleAcc = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\VespaModC#project\\Database\\Accounts.accdb;");
if (i == true)
{
OleDbDataAdapter AdAcc = new OleDbDataAdapter();
OleAcc.Open();
AdAcc.InsertCommand.Connection = OleAcc; // connects data adapter to
AdAcc.InsertCommand.CommandText = "SELECT [Password] FROM Accounts where Email = " + tbemail.Text.ToString() + ""; // runs the query
AccDS.Clear(); // clears dataset
int AccDSPW = AdAcc.Fill(AccDS, "Password"); // fills dataset with data
if (AccDSPW > 0)
{
DataTable dtacc = AccDS.Tables["Password"]; // puts found password in data table
String PW = dtacc.ToString(); // converts data table to string for validation
if (tbpassword.Text == PW) // checks if password matches
{
OleAcc.Close();
this.Hide(); // opens
Main MainForm = new Main(); // main
MainForm.Show(); // form
}
else // Password Does Not Match
{
dbIP incpwform = new dbIP(); // Incorrect password diag box
incpwform.Show();
}
}
}
else // Email does not match
{
dbIEA incemform = new dbIEA(); // Incorrect Email diag box
incemform.Show();
}
}