Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have A button To add User, if i click Button a pop Up comes to add user,

But While Saving I am getting a exception user id not supplied to procedure..

In Table login userid is int not null.


I kept a debugger and tried @userid is null..And procedre is expecting a parameter @userid, where i am going wrong ,

Any stored procedre problem, any suggestions to change my stored procedre

ideas??

suggestions??

What I have tried:

SQL
ALTER PROCEDURE logins @UserId VARCHAR(50)
	,@UserName VARCHAR(100)
	,@FirstName VARCHAR(100)
	,@LastName VARCHAR(100)
	,@Email VARCHAR(200)
	,@Password VARCHAR(100)
	,@AllNames VARCHAR(max)
AS
BEGIN
	IF @UserId IS NULL
		INSERT INTO logins (
			UserName
			,FirstName
			,LastName
			,Email
			,ROLE
			,DateCreated
			,DateModified
			,Password
			,Allnames
			)
		VALUES (
			@UserName
			,@FirstName
			,@LastName
			,@Email
			,'Admin'
			,GetDate()
			,GetDate()
			,@Password
			,@allnames
			)
	ELSE
		UPDATE logins
		SET UserName = @UserName
			,FirstName = @FirstName
			,LastName = @LastName
			,AllNames = @Allnames
		WHERE UserId = @UserId
END
Posted
Updated 17-Mar-17 7:03am
v3
Comments
[no name] 17-Mar-17 11:15am    
userid is int
UserId varchar(50)

Do you see something wrong with these two lines?
And the error message is clear. You are calling your stored procedure and not supplying the user id parameter that it expects.
Mahesh2223 17-Mar-17 11:19am    
That automatically generates id's based on users
Mahesh2223 18-Mar-17 1:17am    
U are correct I changed to int , its working , thnx man
ZurdoDev 17-Mar-17 11:20am    
"a exception user id not supplied to procedure.." - That means your c# code did not send the parameter. Click Improve question and post the c# code where you call this stored procedure.
farid.masood 17-Mar-17 13:11pm    
What is the datatype of your UserID column? I mean you are declaring it as VARCHAR but what is the type in the actual column?

1 solution

Set @UserId VARCHAR(50)=null.
If UserID in an integer field then take parameter as Int.

EX:
ALTER PROCEDURE logins @UserId int = null
,@UserName VARCHAR(100)
,@FirstName VARCHAR(100)
,@LastName VARCHAR(100)
,@Email VARCHAR(200)
,@Password VARCHAR(100)
,@AllNames VARCHAR(max)
AS
BEGIN
IF @UserId IS NULL
INSERT INTO logins (
UserName
,FirstName
,LastName
,Email
,ROLE
,DateCreated
,DateModified
,Password
,Allnames
)
VALUES (
@UserName
,@FirstName
,@LastName
,@Email
,'Admin'
,GetDate()
,GetDate()
,@Password
,@allnames
)
ELSE
UPDATE logins
SET UserName = @UserName
,FirstName = @FirstName
,LastName = @LastName
,AssignedGroups = @Allnames
WHERE UserId = @UserId
END
 
Share this answer
 
Comments
Mahesh2223 18-Mar-17 1:13am    
Thanks Dude its working ,But dono I want to rate it 5 it is not taking my rating
Ramesh Kumar Barik 18-Mar-17 14:16pm    
Welcome Dude. :) Keep coding..

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