Click here to Skip to main content
Sign Up to vote bad
good
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
_Amy43.2K


1 solution

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
Your Filters
Interested
Ignored
     
0 Christian Graus 544
1 Michael Haephrati 390
2 OriginalGriff 233
3 Ron Beyer 220
4 samadhan_kshirsagar 219
0 Sergey Alexandrovich Kryukov 6,959
1 Prasad_Kulkarni 3,689
2 OriginalGriff 3,402
3 _Amy 3,332
4 CPallini 2,950


Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid