Click here to Skip to main content
15,910,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all,
I am creating a function for insert to any table. I am passing table name as parameter and datatype of field. but the problem is how we should decide the number of fields passing?
Plz help....
Posted
Comments
Albin Abel 3-Mar-11 3:47am    
Your question is not clear. Are you saying insert into a table without knowing what are the fields it has? That is not the correct way
Sweetynewb 3-Mar-11 5:39am    
We know the fields of table but this function can be used with different tables so 1st parameter of function will be Name of "table" and 2nd will be value for the field. Now i want to know how dynamically i should set those values to fields
Sandeep Mewara 3-Mar-11 3:48am    
Not sure/clear. It's your database, your table, you should be able to know and pass on whatever is needed!

If you're dynmically building the SQL statement as a string, you can do this. But, of course, this opens you up to SQL Injection attacks and you have to build the complete statement every time you use it.

If you're talking about sending the table name using an SqlParameter object, you can NOT do that. It won't work.
 
Share this answer
 
have a look at this, BUT it only works with SQL Server 2008

CodeProject Article: TableValueParameters[^].

if this doesn't do what you are after read up on LinQ to SQL
 
Share this answer
 

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