Reading text file using ADO.net

  • Thread starter Thread starter Simon Verona
  • Start date Start date
S

Simon Verona

Not sure if this is the best group... it may be better off in one of the ADO
groups, but I'm sure somebody here knows the answer:

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
 
Hi Simon,

I am also not sure if this is the wrong group, but I am sure that you are
missing a command.

Dim cmd As New OleDbCommand(sqlStr, Conn)
Dim da As New OleDbDataAdapter(cmd)

Not saying that I know of the rest works.

But maybe it was only this?

Cor
 
Back
Top