CSV file into dataset

  • Thread starter Thread starter EMW
  • Start date Start date
E

EMW

Hi,

I have a CSV file where the fields are inclosed in " and separated by ,

i.e.: "field1","field2","field3",..... etc.

Is it possible to fill a dataset in an easy way?
I can write my own methode to read it line by line, but then it would take
longer.

I know about the FAQ from www.syncfusion.com but when I use that, I only get
one column with everything.
Is there any other way?

thanks,
Eric
 
Hi EMW

Here a sample, but the delimiter has to be in your culture setting.
(It goes about that FMT=Delimited\)
But that is very dependable on your culture settings, so you have to try.

Cor

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\Test1\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
DataGrid1.DataSource = ds.Tables(0)
End Sub
I hope this helps a little bit?
///
 
Hi EMW,

Here a sample, the point is the FMT=Delimeted\
The delimeter has to be in your culture settings way.
So with that you have to play

I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim file As String = "Test2.txt"
Dim path As String = "C:\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(path & file) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
path & ";Extended Properties=""Text;HDR=No;FMT=Delimited\"""
Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
file, conn)
da.Fill(ds, "TextFile")
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
DataGrid1.DataSource = ds.Tables(0)
End Sub
///
 
Back
Top