I have a DB with a table called person
with two rows called personID
and firstName
Now, I have a form with 2 text boxes, asking for an ID and a first name.
Thing is, I have no idea how to go about checking the DB if the ID and the firstName are from the same record and taking you to another form called admin
if the records match and if they don't just giving an error label.
I would love any help with this, thank you.
EDIT: This is the code as of now, getting the connection already open, connection must be open
error
private void btnLoginScreen_Click(object sender, EventArgs e)
{
{
switch (dbAuth(txtAdminLogID.Text, txtAdminLogName.Text))
{
case true:
//Open Admin form
break;
case false:
//Show Errorlabel here
break;
case null:
//An error occured while fetching data
break;
default:
break;
}
}
}
public bool? dbAuth(string personID, string firstName)
{
try
{
MySqlCommand command = new MySqlCommand();
command.CommandText = "SELECT * FROM person";
MySqlDataReader Reader;
conn.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
if (Reader[0].ToString() == personID) //first check if the ID is equal
{
if (Reader[1].ToString() == firstName) //if ID is equal, check if firstName is equal
{
conn.Close();
return true;
}
}
}
conn.Close();
return false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
EDIT: This is my connection string:
string connstring = "server=localhost;user Id=root;database=collegesystem;Convert Zero Datetime=True ";
MySqlConnection conn;