C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

Procedure or Function has too many arguments


Posted Date: 04 Dec 2008      Posted By: nevermind      Member Level: Bronze     Points: 1   Responses: 3



error:the insert failed 'coz the Procedure or function spInseruserRoles has too many arguments



here's the c# code:[DAL, the code is based on a 3 tier architecture]
sqlconnection.......;[the basic connection ]
SqlParameter objParam;

objParam = new SqlParameter("@RoleName", SqlDbType.VarChar);
objParam.Value = (RoleName);
objCommand.Parameters.Add(objParam);

objParam = new SqlParameter("@UserID", SqlDbType.Int);
//objparam.Direction = ParameterDirection.Output;
objParam.Value = Convert.ToInt32(UserID);
objCommand.Parameters.Add(objParam);



objCon.Open();
objCommand.ExecuteNonQuery();


Th sql storedproc:

alter PROCEDURE [dbo].[spInsertUserRoles]
(
@RoleName varchar(50),
@UserID INT
--@Result INT OUTPUT
)
-- WITH ENCRYPTION
AS
BEGIN
SET NOCOUNT ON
Declare @RoleID int
SELECT @RoleID = RoleID FROM dbo.Roles WHERE RoleName like @RoleName

IF NOT EXISTS (SELECT 1 FROM dbo.UserRoles WHERE RoleID = @RoleID and UserID = @UserID )
BEGIN



INSERT dbo.UserRoles
(
RoleID , UserID
)
VALUES
(
@RoleName ,@UserID
)

--SELECT @Result = 1
END
ELSE
-- SELECT @Result = 0
SET NOCOUNT OFF
end





Responses

Author: Sravya    04 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 1

Visit the blog, it will helps you alot
www.codesnippetforyou.blogspot.com

thanks and regards



Author: Pradeep Iyer    04 Dec 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hi,

Here in the INSERT statement, you are only passing two values while you have three fields in your table.

The number of fields should match exactly with that in the table.

Regards,
Pradeep Y

Regards,
Pradeep Iyer



Author: Mohsin Mehmood    04 Dec 2008Member Level: SilverRating: 3 out of 53 out of 53 out of 5     Points: 3

I think this portion of your sp code is causing the problem

INSERT dbo.UserRoles
(
RoleID , UserID
)
VALUES
(
@RoleName ,@UserID
)

You are Inserting @RoleName in RoleID column and datatype
of RoleID may be set to Int.

Hope this Helps
Mohsin Mehmood



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Diference between .net2005 and .net2008
Previous : Bulk Mail Server using C#
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use