Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am create login form in that i have active/inactive combobox from where admin select active and inactive value and active and inactive user.
how can i check this at the time of login.i check with username and password how i check with if user is active or not.how can i check with username and password.
C#
const string query1 = ("Select * from emp_tracker_username where username=@username and password=@password");
//cn.Open();
OleDbCommand cmd1 = new OleDbCommand(query1, cn1);
cmd1.Parameters.AddWithValue("@username", txtusername.Text);
cmd1.Parameters.AddWithValue("@password", txtpassword.Text);
OleDbDataAdapter ad1 = new OleDbDataAdapter(cmd1);
DataSet dt1 = new DataSet();
ad1.Fill(dt1);
if (dt1.Tables[0].Rows.Count > 0)
{
    Form f4 = new frmCorporateNewid();
    f4.Show();
    // hiding the first form.
    this.Hide();
}
else
{
    MessageBox.Show("Login Unsucessful...!");
}
Posted
Updated 21-Sep-12 1:26am
v2

1 solution

You need to modify your command. Try this:
C#
const string query1 = ("Select * from emp_tracker_username where username=@username and password=@password");
//cn.Open();
OleDbCommand cmd1 = new OleDbCommand(query1, cn1);
cmd1.Parameters.AddWithValue("@username", txtusername.Text);
cmd1.Parameters.AddWithValue("@password", txtpassword.Text);
OleDbDataAdapter ad1 = new OleDbDataAdapter(cmd1);
DataSet dt1 = new DataSet();
ad1.Fill(dt1);
if (dt1.Tables[0].Rows.Count > 0)
{
    //Active is the table column which is there in datatable of type BIT/Boolean fetched from database
    if(Convert.ToBoolean(dt1.Tables[0].Rows[0]["Active"])){
        //If use is active
        Form f4 = new frmCorporateNewid();
        f4.Show();
        // hiding the first form.
        this.Hide();
    }
    else{
        //Show the message if user is inactive.
        MessageBox.Show("User is inactive. Contact your admin");
    }
}
else
{
    MessageBox.Show("Login Unsucessful...!");
}



--Amit
 
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