Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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))
as
begin
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
else
return 0
end

C# Code Below

SqlConnection con = new SqlConnection(Constr);
SqlCommand cmd = new SqlCommand("Authenticate",con);
cmd.Parameters.AddWithValue("@Pname", productname);
cmd.Parameters.AddWithValue("@CategoryName", categoryname);
con.Open();
int ctr = (int)cmd.ExecuteScalar();
con.Close();
return ctr;
Posted
Updated 12-Apr-13 2:13am
v6
Comments
[no name] 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.

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
 
Share this answer
 
Comments
surendranew 12-Apr-13 8:14am    
i have updated the question manfred please see one more time
Hi,

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 ADO.net


http://www.c-sharpcorner.com/UploadFile/rohatash/get-out-parameter-from-a-stored-procedure-in-Asp-Net/[^]

http://www.aspdotnet-suresh.com/2012/07/get-output-parameter-from-stored.html[^]
 
Share this answer
 
v2

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