Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
The most efficient way for Passing DataTable to Stored Procedure is by using User Defined Table Type. But it requires that column names must be known prior to creating table type.

My requirement is to pass random columns to SP. Is it possible to pass DataTable whose columns are always random to Stored procedure.

Any help or suggestion...

What I have tried:

Searching a lot on google & tried with http://www.aspsnippets.com/Articles/Send-Pass-DataTable-as-parameter-to-Stored-Procedure-in-C-and-VBNet.aspx , http://www.codeproject.com/Articles/412802/Sending-a-DataTable-to-a-Stored-Procedure etc etc
Posted
Updated 17-Apr-16 22:20pm
v2

1 solution

Well, yes - it does. But that's for a good reason.
Column names are needed because they are what the stored procedure uses to access the Table data once it arrives - and if you don't specify the column names, the SQL Table can't be created, and the SP couldn't access them if it was. SQL will not work with "column indexes" except by some very nasty fiddling around.

So give the columns "generic names" - "C1", "C2", ... and both ends will work fine.
 
Share this answer
 
Comments
Umesh AP 25-Apr-16 8:33am    
That means i have to create maximum columns with generic names eg C1, C2, C3,... may be of VARCHAR datatype and pass required columns only while other contains null values.

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