Opening a dbf file with .NET code

G

Guest

I have a simple dbf file with the name of OTHWAGE.dbf. I can open it in
Visual Studio Server Explorer and see its fields and records by creating a
Data Connection. When I copy the connection string and combine it with code
from VS Help, I end up with the following:

Dim sConnection As String = "Provider=MSDASQL.1;
Persist Security Info=False;
Data Source=dBASE Files;
Extended Properties=""DSN=dBASE Files;DBQ=C:\Temp;
DefaultDir=c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE;
DriverId=533;MaxBufferSize=2048;
PageTimeout=5
;"";
Initial Catalog=C:\Temp"

Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
Dim myConnection As New System.Data.Odbc.OdbcConnection(sConnection)
Dim myCommand As New System.Data.Odbc.OdbcCommand(mySelectQuery,
myConnection)
myConnection.Open()
Dim myReader As
System.Data.Odbc.OdbcDataReader = myCommand.ExecuteReader()
While myReader.Read()
Console.WriteLine(myReader.GetString(1))
End While

For readability purposes, I added carriage returns to the connection string.
When I execute this code, I get a system error at the myConnection.Open()
line. What I am I doing wrong with this simple code?
 
G

Guest

I agree it should work. This time I even began a new project (on same
computer). One form, one button. FoxPro provider worked great in the Server
Explorer.

I crash at last line of code shown below:

Dim sConnection As String = "Provider=VFPOLEDB.1;Data Source = C:\Temp;"
Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
Dim myConnection As New System.Data.Odbc.OdbcConnection(sConnection)
Dim myCommand As New System.Data.Odbc.OdbcCommand(mySelectQuery, myConnection)

myConnection.Open()

Error message is:
An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in
system.data.dll

Additional information: System error.

Thank you for the response. Any more thoughts?
==================
 
G

Guest

I got the following to work:

Dim myConnection As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\TEMP;Extended Properties=dBase III")
Dim myCommand As New System.Data.OleDb.OleDbCommand("SELECT
OTHWAGE.* FROM OTHWAGE", myConnection)
myConnection.Open()
Dim myReader As System.Data.OleDb.OleDbDataReader =
myCommand.ExecuteReader()
While myReader.Read()
Debug.WriteLine(CStr(myReader.GetValue(0)))
End While
 

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