Click here to Skip to main content
15,906,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm new to C# I was wondering

When the user logins (in form1, using only their username and password), form2 should display the users employee ID number. Is this possible?

private void LginBtn_Click(object sender, EventArgs e)
{
    string query = "Select * from Employees Where [Employee Username] = '" + Username_txt.Text + "' and [Employee Password] = '" + Password_txt.Text + "'";
    OleDbDataAdapter sda = new OleDbDataAdapter(query, MAcon);

    DataTable dtbl = new DataTable();
    sda.Fill(dtbl);

    //TO-DO:Check login username & Password
    if (dtbl.Rows.Count == 1)
    {
    this.Hide();
    Dashboard main = new Dashboard();
    main.Show();

    }


What I have tried:

private void LginBtn_Click(object sender, EventArgs e)
{
    string query = "Select * from Employees Where [Employee Username] = '" + Username_txt.Text + "' and [Employee Password] = '" + Password_txt.Text + "'";
    OleDbDataAdapter sda = new OleDbDataAdapter(query, MAcon);

    DataTable dtbl = new DataTable();
    sda.Fill(dtbl);

    //TO-DO:Check login username & Password
    if (dtbl.Rows.Count == 1)
    {
    this.Hide();
    Dashboard main = new Dashboard();
    main.Show();

    }
Posted
Updated 10-Apr-18 11:15am

1 solution

This is very possible. I'm assuming DashBoard is your "form2"? If so create property in your Dashboard form2 class called

public string EmployeeID {get;set;}


Then do
Dashboard main = new Dashboard();
main.EmployeeID = dtbl.Rows[0]["EmployeeID"];
main.Show();


Replace "EmployeeID" with whatever the actual field name is in your data table.
this is a rough pseudo code, so it may not be syntactically precise, but its close.

You could also create a property of
public DataTable Employee{get;set;}

and pass the whole datatable if you want and access its info on your dashboard form.
However you want.

Many possibilities.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900