Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
hello all,

I'm passing only two parameters in stored procedure (i.e username and password), but here I want to check whether the user is admin or registered user, for that in table I have separate column named "user_group"... so how can I check that which user is belonging to which group.??

help me out..

thanks in advance..

this is my stored procedure
SQL
ALTER PROCEDURE dbo.LogInProcedure
    @username nvarchar (50),
    @password nvarchar (50)
AS
    SET NOCOUNT ON;
SELECT        user_username, user_password
FROM          users WHERE user_username=@username AND user_password=@password


and this is the execution of this stored procedure
SqlCommand cmd = new SqlCommand("LogInProcedure", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@username", usernametxt.Text);
            cmd.Parameters.AddWithValue("@password", passwordtxt.Text);

            con.Open();

            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();

            if (reader.HasRows)
            {
                Session["uname"] = usernametxt.Text;
                Response.Redirect("Home.aspx");
            }
            else
            {
                loginerrorpanel.Visible = true;
            }
Posted

1 solution

do you know ,what is the priority given for the admin in user_grp?..

I think You will be knowing the priority.

then initially in your sp check the presence of the username and password using

if exists(your query)

then,
declare a variable of your datatype and pass the usergrp for respective password and username.

if the usergrp is same as admin priority..then get the value such as any datatype-data..as output Parameter.and check the parameter in codebehind and then redirect to required page.
 
Share this answer
 
Comments
[no name] 16-Nov-12 0:07am    
Ok I got your point, but can you please alter this SP.??
Nandakishore G N 16-Nov-12 0:23am    
ALTER PROCEDURE dbo.LogInProcedure
@username nvarchar (50),
@password nvarchar (50)
AS
declare @usergrp nvarchar(50)--your required datatype
SET NOCOUNT ON;
if exists (select user_username from users WHERE user_username=@username AND user_password=@password)
begin
set @usergrp =(select user_group from users WHERE user_username=@username AND user_password=@password)
if(@usergrp ='admin')
begin
--set outputparameter of required value to get the identity as admin or authority
end
else
begin
--set something where you can easily identify as user
end
end

just search in google how to use output parameter...
all the best..
[no name] 16-Nov-12 1:37am    
Thanks man.. :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900