Open a CSV file

S

Stefke

Hi,

I've exported our Exchange 5.5 server info into a CSV file. I know want to
create a VB.Net application which reads the CSV file and then process the
information in it.

Can anyone tell me what I should do to create the application. The file is
called info.csv.
And I want to process it row by row.

Kind Regards

Stefke
 
P

Pipo

Hi Stefke,

dim SR as New StreamReader("c:\My Documents\info.csv")
dim txtLine as String
dim Strings as String()
txtLine = SR.ReadLine()
Strings()=String.Split(",",txtLine)
 
H

Herfried K. Wagner [MVP]

Stefke said:
I've exported our Exchange 5.5 server info into a CSV file. I know want
to
create a VB.Net application which reads the CSV file and then process the
information in it.

Can anyone tell me what I should do to create the application. The file
is
called info.csv.
And I want to process it row by row.

<URL:http://www.connectionstrings.com/>
-> "Text"
 
C

Cor Ligthert

Stefke,

\\\
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?

Cor
 
S

Simon Verona

It should be noted that whilst this would "normally" work, it will fail if
the data contacts a comma ... eg

"hello","this has a comma, see!!",100

You would need to parse the string looking for opening and closing quotation
marks and taking commas between them as part of the data and not a
delimiter.

Herfried and Cor's suggestion for using the text connection string would do
this for you...

Regards
Simon
 

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