Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim data As DataTable = RetrieveSourceData() CopyData(data) End Sub Private Function RetrieveSourceData() As DataTable Dim connstring As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\temp\;Extended Properties='text;HDR=No;FMT=TabDelimited'" Dim sourcedata As New DataTable Using conn As New OleDb.OleDbConnection(connstring) conn.Open() Dim command As New OleDb.OleDbCommand("Select * from X1.CSV", conn) Dim adapter As New OleDb.OleDbDataAdapter(command) adapter.Fill(sourcedata) conn.Close() End Using Return sourcedata End Function Private Sub CopyData(SourceData As DataTable) Dim dbConnString As String = "Data Source=(local);Initial Catalog=XtractDB;User ID=xxxx;Password=yyyy;" Using bcp As New SqlClient.SqlBulkCopy(dbConnString) bcp.DestinationTableName = "X1" bcp.BatchSize = 1000 bcp.WriteToServer(SourceData) End Using End SubIn order for the input file to be recognised as TabDelimited I have had to create a schema.ini file in the same directory as the input file. The contents are shown below
[X1.CSV] Format=TabDelimitedIs there any way I can force the fields with spaces not to be treated as NULL when creating the DataTable?