How to use vb.net BulkCopy

'Create a new StopWatch to measure the
' amount of time it takes to perform the
' insert
Dim swatch As New Stopwatch()
swatch.Start()
'Configure the connection string
Dim cnString As String = "Data Source=;Initial Catalog=;Integrated Security=False;User ID=;Password=;"
'Create a new SqlBulkCopy class
Dim bcp As New SqlClient.SqlBulkCopy(cnString, SqlClient.SqlBulkCopyOptions.KeepNulls)
'You MUST specifiy the table you are going to fill
bcp.DestinationTableName = "Table Name"
'Increase the timeout to a more appropriate time
' for the amount of data your are inserting.
' The default is 30 seconds
bcp.BulkCopyTimeout = 6000
'Write the data to the SQL Server Database table
bcp.WriteToServer(Data Table)
'Close the instance
bcp.Close()
'Stop the Stopwatch!
swatch.Stop()
MsgBox("Done! Elapsed Milliseconds: " & swatch.ElapsedMilliseconds)

Guess you like

Origin www.cnblogs.com/revgin/p/12745140.html