Hi there,i have joined newly to this site....I am a learner as off now.i am developing a windows application using c#.net..
I have two types of users Admin and Normal users.
I am having one login screen.i want the application to identify the two types of users when they enter their username and password.
i saw the post of using session in asp.net,but how to initialize the session and how to use it and how to identify the two types of users who are in the same table.

The user login details for both admin and normal users are in a single table called account..
Table account
uId Pwd
(for admin) admin admin
(for normal user) counter counter
Help me out dude......
Thanks in advance......

Recommended Answers

All 14 Replies

In UserClass define UserType enumerator and assign it a value (came from database userTable) indicates it as an admin or user

Well Dear ....... u r saying u r developing a Windows Application ........There is nothing like Session in Windows app.....Session are used in Web app.
is there any Flag....in ur user table.....???
if it has.....then u can check it in ur query.....

No flag needed, he must put a foreign key in UserTable to identity UserType (Admin or User)
About session, I didn't notice :$

Okay i thought.....he/she uses the single table....actually he/she writes...."The user login details for both admin and normal users are in a single table called account.."
if the user Type (admin or normal user) details are in the other table....then u must have to use the foreign key.........
thanx Ramy

Hey fellows,
Thanks for the replies dudes...
Like ramy said the use of foreign key is necessary if i have two tables.but i am having a single table called account...

I will explain it clearly.
I have a login form where both admin and normal users enter.

The login details are in a single table called account which has the user name and password of both type of users..

If admin logs in he should be taken to a different form and if normal user logs in he should be taken to a different form..

I should do this by taking the user name..I should identify the user(super or normal) by the user name he enters in textbox1...see the code

        if ((textBox1.Text == "") || (textBox2.Text == ""))
            {
                label3.Visible = true;
                label3.Text = "User name or Password is left blank";
                return;
            }
            Con = new SqlConnection("Server=PSTLCORPSERV;database='booking';user id=sa;password=sqlserver12#");
            Con.Open();
            Cmd = new SqlCommand("select * from account where uname=@name and password= @pwd", Con);                      
            Cmd.Parameters.Add("@name", SqlDbType.VarChar);
            Cmd.Parameters.Add("@pwd", SqlDbType.VarChar);
            Cmd.Parameters[0].Value = textBox1.Text;
            Cmd.Parameters[1].Value = textBox2.Text;
            Data = Cmd.ExecuteReader();
            if (Data.Read() == true)
            {

                label3.Text = "valid user";
                Admin_Page ad = new Admin_Page(textBox1.Text);
                ad.Show();
                this.Hide();

add new column in your user table to identify the user type, sure you can't do that using just username and password!!!

Come on, man. Add a column "UserType" with a value of 0 or 1. 0 for admin, 1 for user. When you check the username and password, also grab the value from that column.

ok i have added a new column in my user table called utype..In my code i have written

Cmd = new SqlCommand("select * from account where uname=@name and password= @pwd and utype =@type", Con);

            Cmd.Parameters.Add("@name", SqlDbType.VarChar);
            Cmd.Parameters.Add("@pwd", SqlDbType.VarChar);
            Cmd.Parameters.Add("@type", SqlDbType.Int);            Cmd.Parameters[0].Value = textBox1.Text;
            Cmd.Parameters[1].Value = textBox2.Text;
            Data = Cmd.ExecuteReader();
            if (Data.Read(0) == true)
            {

                label3.Text = "valid user";
                Admin_Page ad = new Admin_Page(textBox1.Text);
                ad.Show();
                this.Hide();
            }
                else if (Data.Read(1)==true)                {
                    Seat_Book sb=new Seat_Book();
                    sb.Show();
                    this.Hide();
                }

How to grab that value in my code...
But it is not working.It is saying that no overload for method read takes 1 arguments..Where to use this logic and what code should i use dudes...
I am going to enter only user name and password in my login page...It should fetch the value from the database based on the username i give in textbox1......
Is this possible fellows.....

Why this "and utype =@type" in your select statement??!!!! you want to filter selected user by utype ??! as you don't know his\her type at all

what you need to modify is to add new column in user table and select userID and uType using user name AND password!

Assign user object ID property with id returned from DB and also uType property (enum).

before calling a method check uType to authorize the current user.

P.S: DataReader.Read() doesn't take any arguments!! to loop for many records (and you don't need that in your case) use while loop

like

while(reader.Read())
{
///some sort of code goes here!
}

By using this query u'll get one Result.......from that u can check......userType

string st=Data["UserType"].ToString();
if(st=="Admin")
{//Open Admin Form}
else if(st=="User")
{// Open User Form}

Enum is better.

Yes Enum is Better.....approach....as Ramy says...

Thanks Buddies,i got it work by using enum and i also tried like saurab said.It also worked..Thank u very much in taking an effort to solve this issue.i am marking this post as solved....Check out my next post.....Ha Ha

hii,i want to make Multiple user login Login using Sql server 2008 R2(Not Store Procedure).can u help me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.