oledb invalid path...

T

tascien

This code is NOT working. Well, the error is saying that the path is
invalid. But how... Before i open the connection, i am doing, if
f.Exists(file) then. so, if that returns true, why the connection
thinks that the file does not exists?

Thanks for your help...

Private Sub dsConn()
Dim file As String = "mt.csv"
Dim ds As New DataSet

Try
Dim f As System.IO.File
If f.Exists(file) Then
Dim ConStr As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
file & ";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
MsgBox(ex.Message) <- invalid path. Make sure the file
exists... blah blah...
End Try
End Sub
 
P

Paul Clement

¤ This code is NOT working. Well, the error is saying that the path is
¤ invalid. But how... Before i open the connection, i am doing, if
¤ f.Exists(file) then. so, if that returns true, why the connection
¤ thinks that the file does not exists?
¤
¤ Thanks for your help...
¤
¤ Private Sub dsConn()
¤ Dim file As String = "mt.csv"
¤ Dim ds As New DataSet
¤
¤ Try
¤ Dim f As System.IO.File
¤ If f.Exists(file) Then
¤ Dim ConStr As String =
¤ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
¤ file & ";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
¤ MsgBox(ex.Message) <- invalid path. Make sure the file
¤ exists... blah blah...
¤ End Try
¤ End Sub

The Data Source should be the path to the file, excluding the file name:

Dim TextConnection As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "E:\My
Documents\TextFiles" & ";" & _
"Extended
Properties=""Text;HDR=NO;""")


Paul
~~~~
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

Similar Threads

CSV File to database. 3
Path to my data file for Jet.OLEDB 16
import csv file in sql table 3
File name problem 2
Leading zero 5
CSV select not reading the first line 4
dataset to array 3
schema.ini not working 2

Top