Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
In database i have username,password,department,..
while login time i have to check username and department(in department i have fields are IT, employee, HR )
if username and department(IT) it should b redirect to It Page only
if username and department(Hr) it should b redirect to HR Page only
if username and department(Employee) it should b redirect to Employee Page only
 
and login.aspx i have only two filed user name and password..
 
following is my coding
 
public class LogIn
{
SqlDataAdapter adp;
DataSet ds;
public LogIn()
{
 
}
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrin gs["ConnectionString"].ConnectionString.ToString());
 
public DataSet select(string s)
{
adp = new SqlDataAdapter(s, cn);
ds = new DataSet();
adp.Fill(ds);
return ds;
}
}
in
login.aspx.cs
protected void btn_login_Click(object sender, EventArgs e)
{
DataSet DS = new DataSet();
string s = "select depertment from checkuser where user_name='" + txtusername.Text + "' and password='" + txtpassword.Text + "'";
DS = objlog.select(s);
 
if (DS.Tables[0].Rows.Count > 0)
{
Session["username"] = txtusername.Text;
Response.Redirect("Home.aspx");
}
 
}
m not getting how i wl do this..
reply asap.. m waiting
thank You
Posted 21-Dec-12 20:21pm
Jay Ahuja1.2K
Edited 22-Dec-12 0:10am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

DataSet DS = new DataSet();
 
    string s = "select depertement from tb where username='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'";
 
    DS = objlog.select(s);
 

    if (DS.Tables[0].Rows.Count > 0)
    {
 
        Session["username"] = TextBox1.Text;
        Session["depertementname"] = DS.Tables[0].Rows[0]["depertement"].ToString().ToUpper();
 
        if (Session["depertementname"].ToString() == ("HR"))
        {
 
            Response.Redirect("HrHome.aspx");
 
        }
 
        else
        {
 
            Response.Redirect("Home.aspx");
 
        }
 

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

Solution 4

Namskar(Hi),
 

protected void btn_login_Click(object sender, EventArgs e)
{
DataSet DS = new DataSet();
string s = "select depertment from checkuser where user_name='" + txtusername.Text + "' and password='" + txtpassword.Text + "'";
DS = objlog.select(s);
 
if (DS.Tables[0].Rows.Count > 0)
{
Session["username"] = txtusername.Text;
   if(DS.Tables[0].Rows[0][0].ToString()=="IT")
    {
      Response.Redirect("IT.aspx");
    }
   else if(DS.Tables[0].Rows[0][0].ToString()=="Employee")
    {
      Response.Redirect("Employee.aspx");
    }
   else
    {
      Response.Redirect("Hr.aspx");
    }
 

}
 
}
  Permalink  
Comments
Jay Ahuja at 24-Dec-12 1:18am
   
Thanx a lot.. :) finally i got perfect coding :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

1. You have to store the user type in user table.
2. Verify that username and password are correct.
3. Get user type from database.
4. Open the appropriate page using if-else.

This is too basic solution.
Hope it helps.........

In case you are not satisfied with the solution please let me know.
I will tell you the other way.
 
[Edit]Shouting removed[/Edit]
  Permalink  
v2
Comments
Jay Ahuja at 22-Dec-12 3:00am
   
hello sir, thanx for ur help
the 1st three step m already done wen m trying 4th one itz redirecting to same page only can u please help me for this
AnkitGoel.com at 22-Dec-12 3:03am
   
send your code by which u are redirecting users to different pages
Jay Ahuja at 22-Dec-12 3:14am
   
if (DS.Tables[0].Rows.Count > 0)
{
Session["username"] = txtusername.Text;
if (Session["username"].ToString() == ("Emplpoyee"))
{
Response.Redirect("Home.aspx");
}
else
{
Response.Redirect("HrHome.aspx");
}
 
}
AnkitGoel.com at 22-Dec-12 3:17am
   
in this case which page are u getting redirected?
 
Also, check the spell mistake -emplpoyee- should be 'employee-
Jay Ahuja at 22-Dec-12 3:19am
   
home.aspx
AnkitGoel.com at 22-Dec-12 3:22am
   
try rebuilding your project. this prob should not occur if u are passing something other that 'emplpoyee' in username textbox.
Jay Ahuja at 22-Dec-12 3:22am
   
i had try same for HR also doing geting same Rply
AnkitGoel.com at 22-Dec-12 3:23am
   
i feel u need to debug your app and find out the reason
Jay Ahuja at 22-Dec-12 3:23am
   
in textbox i m have passing username.. only and password in password textbox
AnkitGoel.com at 22-Dec-12 3:24am
   
or i will have to review the complete code behind to be able to investigate the problem
AnkitGoel.com at 22-Dec-12 3:25am
   
why have u kept "emplpoyee" in parentheses?
Jay Ahuja at 22-Dec-12 3:25am
   
please try that sir.. m facing this prblm last 5 days
AnkitGoel.com at 22-Dec-12 3:26am
   
send complete code pls..
Jay Ahuja at 22-Dec-12 3:28am
   
in login.aspx.cs
DataSet DS = new DataSet();
string s = "select depertment from checkuser where user_name='" + txtusername.Text + "' and password='" + txtpassword.Text + "'";
DS = objlog.select(s);

if (DS.Tables[0].Rows.Count > 0)
{
Session["username"] = txtusername.Text;
Response.BufferOutput = true;
 

if (Session["username"].ToString() == "HR")
{
Response.Redirect("HrHome.aspx");
}
else
{
Response.Redirect("Home.aspx");
}
 
}
}
in class file i have
public class LogIn
{
SqlDataAdapter adp;
DataSet ds;
public LogIn()
{
 
}
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString());
 
public DataSet select(string s)
{
cn.Open();
adp = new SqlDataAdapter(s, cn);
ds = new DataSet();
adp.Fill(ds);
return ds;
 
}

 
}
Jay Ahuja at 22-Dec-12 3:27am
   
if i don't keep in parentheses than also m geting same page
AnkitGoel.com at 22-Dec-12 3:28am
   
tried debugging?
Jay Ahuja at 22-Dec-12 3:28am
   
yup sir.. check my code
AnkitGoel.com at 22-Dec-12 3:30am
   
please debug it and check the value in the textbox.
Jay Ahuja at 22-Dec-12 3:36am
   
wen i debug it itz not checking this condtion
if (Session["username"].ToString() == "HR")
{
Response.Redirect("HrHome.aspx");
}
AnkitGoel.com at 22-Dec-12 3:37am
   
check the condition before this.Are you able to authenticate the user?
Jay Ahuja at 22-Dec-12 3:40am
   
ya.. according to u wat should b code.. can u please tel me that
AnkitGoel.com at 22-Dec-12 3:41am
   
check the values at-
 
string s = "select depertment from checkuser where user_name='" + txtusername.Text + "' and password='" + txtpassword.Text + "'";
 
tell me what u get here?
Jay Ahuja at 22-Dec-12 3:47am
   
had apply wat had given but geting username nd password only not depertement value
AnkitGoel.com at 22-Dec-12 3:51am
   
i said u to check the value of textboxes at following line-
string s = "select depertment from checkuser where user_name='" + txtusername.Text + "' and password='" + txtpassword.Text + "'";
and u are teelling me some other thing.
Jay Ahuja at 22-Dec-12 4:18am
   
m getting this sir
"select depertment from checkuser where user_name='jay' and password='111'"
AnkitGoel.com at 22-Dec-12 4:21am
   
may be ur not getting any row from database for this qry. did u check?
Jay Ahuja at 22-Dec-12 4:26am
   
hello sir can u please send me compelete code of my query??
Jay Ahuja at 22-Dec-12 5:05am
   
sir please help me for this..
AnkitGoel.com at 22-Dec-12 5:07am
   
dear, no one is free to do your work. we can only guide you. there is some bug that u have to resolve by urself. i can't do anything from here.
Jay Ahuja at 22-Dec-12 5:09am
   
ohk sir thanx alot for helping me.. :)
AnkitGoel.com at 22-Dec-12 5:11am
   
As per my understanding, your select query is not producing correct result. you need to check that query.
Jay Ahuja at 22-Dec-12 5:17am
   
in checkuser table i have 4 coloum.. emp_id,username,password,depertment is there should prblm coz for this????
AnkitGoel.com at 22-Dec-12 5:19am
   
how would i know that when i am unable to see ur db ?
Jay Ahuja at 22-Dec-12 5:21am
   
ya.. wrong que.. sorry for this

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 878
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 24 Dec 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