Answered by:
Insert elements from an array into table?

Question
-
Dear all,
I have a table with over 500 fields, name of the fields are F1, F2, ....F500.
How can i insert from an array, or loop through the fields to insert?
I've looked for solution in MSDN and find the statement:
INSERT INTO dbf_name FROM ARRAY ArrayName | FROM MEMVAR | FROM NAME ObjectName
However, it's used for Visual FoxPro in VS2005.
I'm using VS C#, Entity FrameWork.
Pls help me.
thanks.
Thursday, July 14, 2011 3:24 PM
Answers
-
Since each field is a column if your table is in the same order you can use the bulkcopy object
first convert your array into a dataset then create the bulkcopy pointing to the table that you need to insert into.
then simply run the writetoserver(dataset) function and it will fly into your sql database
- Marked as answer by hungdoan Monday, July 18, 2011 2:54 PM
Monday, July 18, 2011 1:34 PM
All replies
-
SQL Server does not support Array parameters. Options would be using either XML or table-valued parameters. Below is an example that uses XML:
How to pass array of values into SQL Server stored procedure using XML and Visual Basic .NET
Paul ~~~~ Microsoft MVP (Visual Basic)Friday, July 15, 2011 2:52 PM -
could you clarify if each field is a new row or is each field a column?
Friday, July 15, 2011 5:44 PM -
thank you for reply, each field is column.
i found the statement: INSERT INTO dbf_name FROM ARRAY ArrayName.
but dont known how to use it in C#.
Saturday, July 16, 2011 3:22 AM -
check this case. http://stackoverflow.com/questions/4720138/insert-into-with-array may be helpful for you.
Thanks,
Esters,
Just a newbie for everything.Monday, July 18, 2011 5:50 AM -
Since each field is a column if your table is in the same order you can use the bulkcopy object
first convert your array into a dataset then create the bulkcopy pointing to the table that you need to insert into.
then simply run the writetoserver(dataset) function and it will fly into your sql database
- Marked as answer by hungdoan Monday, July 18, 2011 2:54 PM
Monday, July 18, 2011 1:34 PM