2012年2月13日星期一

Batch Inserts from DataTable

Please help guys,
I have a DataTable filled from the parsing of a csv file by the OleDb text driver.
This DataTable could on occassion contain in excess of 2000 rows.
I want to be able to batch the inserts to my backend sql table and be able to recorver on errors during the insert.
i.e, maybe send the first 500 rows to insert via an insert dynamic text... really don't know the optimal insert technic to use.
but, if I get an error on say the third batch, I want to be able to recorver, and not have to start all over again and continue the inserts from the batch that failed....
Please help... what is the best way to perform the inserts and how can I track these inserts and recorver on errors like power failures or sql server unavailable etc.
Please help...could I batch the reading of data from a csv file, I mean, if the csv file contains hundreds of thousand of records, how do I read say 500 at a time, using the Microsoft Text Driver - please help...|||

You could run dynamic selects

dim i as int32

for each row in datatable.rows

sql += "insert into table;"
i += 1

if i = 500 then

'do connection and things

i = 0

end if

next

Nick

|||

You could use DTS package to move the CVS file but if you want an alternative, try the links below for options. Hope this helps.

http://www.sqldts.com/?220

http://www.users.drew.edu/skass/sql/TextDriver.htm

没有评论:

发表评论