oledb invalid path...

  • Thread starter Thread starter tascien
  • Start date Start date
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
 
¤ 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)
 
Back
Top