I have made a simple login program that uses an access db that stores usernames and passwords. here is the code for the login button that opens the second form:
private void btnlogin_Click(object sender, EventArgs e)
{
con.Open();
string login = "SELECT * FROM tbluser WHERE username= '" + txtusername.Text + "' and password= '" + txtpassword.Text + "'";
cmd = new OleDbCommand(login,con);
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read() == true)
{
new Form3().Show();
this.Close();
}
else
{
MessageBox.Show("Invalid Username or Password", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtpassword.Text = "";
txtusername.Text = "";
}
}
Form3 has no code, its a blankform. How do display the name of the user that logged in on the blank form? Would i need a seperate table that has a foreign key that points to the user ID? If so how would I code this into the program?
Thanks