import csv file in sql table

G

Guest

Hi,

I'm trying to import data from csv file into a sql table. this is how i read
the information from the file:

=============
Private Sub import_oledb()
da_import.Fill(Ds_import_u)

Dim strPath As String = "c:\test.csv"

Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(strPath) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\" & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)

Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
"test.csv", conn)
da.Fill(ds, "test.csv")

End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

DataGrid1.DataSource = ds.Tables(0)

End Sub
=============================
Now, this fills the ds and binds the datagrid. how do i dump all these rows
in a table in sql database?

I would appreciate any help.

Thank you,
Catalin
 
G

Guest

Hi

There is much fast way to bulk insert file content directly to table in
database:

command.CommandText = "BULK INSERT db_table_name FROM 'c:\test.csv' WITH
(DATAFILETYPE = 'char', FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')"

command.ExecuteNonQuery()

HTH

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top