Reading text file using ADO.net

S

Simon Verona

Hope somebody can help...

I'm trying to load up a text file using ADO.net, as follows:

Dim TextConnectionString As String
TextConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & FilePath & ";" & _
"Extended Properties=""Text;HDR=NO;FORMAT=Delimited"""
Dim TextConn As New System.Data.OleDb.OleDbConnection(TextConnectionString)
TextConn.Open()
Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from " & filename, TextConn)
Dim ds As DataSet = New DataSet("CSVFiles")
da.Fill(ds, filename)


When I run this, it fails at the "fill" statement with the error "Database
or object is read only".

The file in question can definitely be read and written (it's a short CSV
file). What have I done wrong???

Many thanks in advance.


Simon
 
P

Paul Clement

¤ Hope somebody can help...
¤
¤ I'm trying to load up a text file using ADO.net, as follows:
¤
¤ Dim TextConnectionString As String
¤ TextConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
¤ "Data Source=" & FilePath & ";" & _
¤ "Extended Properties=""Text;HDR=NO;FORMAT=Delimited"""
¤ Dim TextConn As New System.Data.OleDb.OleDbConnection(TextConnectionString)
¤ TextConn.Open()
¤ Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from " & filename, TextConn)
¤ Dim ds As DataSet = New DataSet("CSVFiles")
¤ da.Fill(ds, filename)
¤
¤
¤ When I run this, it fails at the "fill" statement with the error "Database
¤ or object is read only".
¤
¤ The file in question can definitely be read and written (it's a short CSV
¤ file). What have I done wrong???
¤

Could you post a few lines from your text file and the actual filename (with extension) you are
using.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

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