Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.5
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.
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 21-Sep-12 1:16am
Edited 21-Sep-12 1:26am
_Amy50.5K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to modify your command. Try this:
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
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100