How to pass parameter from code behind to sqlserver using stored procedure

Posted by Kumaran under C# on 9/3/2014 | Points: 10 | Views : 1326 | Status : [Member] | Replies : 2
create proc test(
@param1 varchar(50)
)
as begin
select * from entity where e_code in (@param1)
end


///code behid c#

i need to send parameter from c# code behind. how to send it?

this is my parameter values '28119,27899' after all checkbox has been selected.




Responses

Posted by: Naveenhcl on: 9/3/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,

you can pass the parameters like below.

protected void Get_Data(string Contract_Id)
{
SqlParameter[] objParams = { new SqlParameter("@Contract_Admin_Id", Contract_Id) };
}


In the above code part Contract_Id is the input parameter it will passed to procedure and get result from procedure based on this input parameter.

Kumaran, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/4/2014 [Member] [MVP] Platinum | Points: 25

Up
0
Down
First get all selected values from check box and have those into a string and then pass that comma separated value list ( as string) to the stored procedure input parameter...

Refer
http://forums.asp.net/t/1489903.aspx
http://stackoverflow.com/questions/18460242/how-to-pass-multi-value-of-checkbox-list-to-stored-procedure-in-code-behind
http://forums.asp.net/t/1616223.aspx


SP is:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[reports_customer](
@id varchar(100)
)
as begin
select * from dbo.cust_details where ','+@id+',' like '%,'+ cast(cust_ID as varchar(100))+ ',%'
end


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kumaran, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response