Click here to Skip to main content
11,496,146 members (48 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: 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 at 14-Nov-12 8:31am
Rob@Love2Code at 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.....

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

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 at 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
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2015
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