Click here to Skip to main content
12,504,984 members (63,422 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# SQL stored-procedure
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
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 15-Nov-12 17:54pm

1 solution

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

Solution 1

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.
  Permalink  
Comments
Krunal R 16-Nov-12 0:07am
   
Ok I got your point, but can you please alter this SP.??
Nandakishorerao 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..
Krunal R 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160919.1 | Last Updated 16 Nov 2012
Copyright © CodeProject, 1999-2016
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