Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
Comments
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.....
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

Solution 2

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
  Permalink  
Comments
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 DamithSL 320
1 OriginalGriff 155
2 Peter Leow 115
3 Afzaal Ahmad Zeeshan 114
4 deepakdynamite 110
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 4,994
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2014
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