Click here to Skip to main content
11,928,732 members (56,859 online)
Rate this:
Please Sign up or sign in to vote.
See more: .NET ADO.NET
hi i have wrote a stored procedure which returns one output value i have to read that value in my code which was giving me an error please correct
create proc Authenticate(@Pname varchar(50),@categoryname varchar(55))
declare @productcount int
declare @categorycount int
set @productcount=(select count(*) from Product where Pname=@Pname )
set @categorycount=(select count(*)from Category where CategoryName=@categoryname)
if(@productcount!=0  @categorycount!=0)
return 1
return 0
C# Code Below

SqlConnection con = new SqlConnection(Constr);
SqlCommand cmd = new SqlCommand("Authenticate",con);
cmd.Parameters.AddWithValue("@Pname", productname);
cmd.Parameters.AddWithValue("@CategoryName", categoryname);
int ctr = (int)cmd.ExecuteScalar();
return ctr;
Posted 12-Apr-13 1:17am
Edited 12-Apr-13 3:13am
ThePhantomUpvoter 12-Apr-13 9:12am
Would really be helpful if you told us what the error was instead of trying to make us guess. You need to set the command type to be CommandType.StoredProcedure.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you read the code example of SqlParameterCollection.AddWithValue here[^] you'll see that you're missing the @ prefix of the parameter's name.

— Manfred
surendranew 12-Apr-13 8:14am
i have updated the question manfred please see one more time
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


If you want to display the error message using StoredProcedure then you must create one output parameter and then call that parameter in your code, please refer below link to get output parameter from StoredProcedure to[^][^]

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
Web03 | 2.8.151126.1 | Last Updated 12 Apr 2013
Copyright © CodeProject, 1999-2015
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