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
_Amy49.3K
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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 459
1 Nirav Prabtani 338
2 _Amy 170
3 PIEBALDconsult 160
4 Abhinav S 160
0 OriginalGriff 7,640
1 Sergey Alexandrovich Kryukov 6,836
2 Maciej Los 3,919
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web04 | 2.8.140721.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