Click here to Skip to main content
12,749,465 members (31,995 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0
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 14-Nov-12 3:24am
Nelek 14-Nov-12 8:31am
Rob@Love2Code 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.....
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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.

Create procedure proc_DynamicFields(@items varchar(max))
declare @sql varchar(max)

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


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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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.

Tapan kumar
Marcus Kramer 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2017
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