المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Help with a Log-in Screen



C# Programming
04-14-2010, 10:30 PM
Hey everybody, if somebody can help me with this I'd really appreciate it. I'm currently writing a Ticketmaster esque program, in which we have to have a user log-in and out of the program. Well I have a main form, and a log-in form. The user clicks a linked label on the main form to load up the log-in form. Sign in with their credentials and click the log-in button on the log-in form. I have it reading from and checking an access database file to make sure that they have log-in information and that it is correct. What I need now is to be able to pass the [username] from the database that they use on the login form back to the main form, so that the program can recognize if an administrator logs in. Here is my main form code for the log-in button:
private void lnklblLogIn_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
sp.Stop();
frmLogIn LogIn = new frmLogIn();
LogIn.Show();
}
and here is my log-in form code for the log-in button:
private void btnLogIn_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\John\\Desktop\\Database1.mdb");
OleDbCommand com = new OleDbCommand("SELECT UserName, PassWord FROM Table1",con);
OleDbDataReader reader;

bool permit = false;

try {
con.Open();
reader = com.ExecuteReader();
while (reader.Read())
{
if (txtUserName.Text == (reader["UserName"].ToString()) && mtxtPassWord.Text == reader["PassWord"].ToString())
{
permit = true;
break;
}
}

con.Close();
}
catch {
MessageBox.Show("File not able to be read");
return;
}

if (permit != true)
MessageBox.Show("Username or Password are not correct.");
else {
Close();
}

}
So again my issue is being able to get the username logged in with on the "Log-in" form back to the main form so the main form knows who has logged in. If somebody can help me with this I'd really appreciate it