Click here to Skip to main content
Sign Up to vote bad
good
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 2:24am

Comments
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.....

2 solutions

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  
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 - 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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 6,824
1 Prasad_Kulkarni 3,671
2 _Amy 3,312
3 OriginalGriff 3,309
4 CPallini 2,925


Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 15 Nov 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid