Click here to Skip to main content
15,891,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
My question is like ,i have two DropDownList.

1. From first DropDownList user will select table.
2. From second DropDownList user will select multiple columns based on the selected table from DropDownList 1st.

So i want to pass selected table (from 1st ddl) and multiple columns (from 2nd ddl) as a parameters in sql Stored Procedure.

Note: i want to pass columns as array.

Please Help.
Posted
Comments
Vipin Patil 8-Jun-15 1:50am    
You want to pass array of columns to sql stored procedure or other class
Merajuddin Ansari 8-Jun-15 1:55am    
Yes i want to pass array of columns to the sql stored procedure.
Vipin Patil 8-Jun-15 2:07am    
if you have varchar parameter then
You can concate the values and pass to the stored procedure
Merajuddin Ansari 8-Jun-15 2:10am    
Can you please give an example for that.?
Vipin Patil 8-Jun-15 2:22am    
can we select multiple values from dropdownlist

1 solution

C#
C#
string strCols = "";
foreach (string strVal in DropDownList1.SelectedIValues)
{
      strCols = strCols + strVal + ",";
}

pass strCols to stored procedure
C#
cmd.Parameters.AddWithValue("@Cols", strCols);



SQL

SQL
ALTER PROCEDURE [dbo].[proc_test]
(
   @cols nvarchar (MAX),
   @tablename nvarchar(250)
)
AS
DECLARE @Query varchar(MAX)
SET @Query = 'SELECT ' + @cols + ' from ' + @tablename

EXEC(@Query)
 
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