Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have to use stored procedure that select different number of fields in c#
i don't know how much are the fields or what are

i am working in c#
Posted
Comments
Nelek 14-Nov-12 8:31am    
Rob Branaghan 14-Nov-12 9:19am    
You could create an SQL Stored Procedure that accepts a parameter which is comma seperated values.... but the issue with that is it isnt safe.

I would suggest not writing SQL like that, to be safe.....

Hi,

I am not able to understand what you want to do if you can then explain your problem with a example and still as your question in am giving answer,

You can pass the name of fields using comma separation and in stored procedure you can directly use.

you can use like below example.

SQL
Create procedure proc_DynamicFields(@items varchar(max))
as
Begin
declare @sql varchar(max)

set @sql = 'select ' + @items + ' from tbl_TableName'

Exec(@sql)
End


You can call above Procedure in c# add fill Data Adapter after that you can get the dynamic fields of particular table in Data Adapter.

Hope, it will Work
Thanks
 
Share this answer
 
v2
Hi,

Will you please clarify what your are trying to ask. Please explain the thing a bit otherwise how can one be able to help you out.

Thanks
Tapan kumar
 
Share this answer
 
Comments
fjdiewornncalwe 15-Nov-12 11:00am    
Please use the "Have a Question or Comment" option instead of the "Add your solution here" option when you are asking for more information, etc.

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