How do I open a dbf table in VB Express?

  • Thread starter Thread starter Erik Edlund
  • Start date Start date
E

Erik Edlund

I am trying to open a table in dbf format using VB
Express. There seems to be no explicit provider
alternative. A few of the providers reports that
"Test connection succeeded.", but when I try to
use the connection I get the message "Unable to
connect to database. This feature is not supported
by M$ VB Express."

Is this a dead end or is there a workaround? I
need to read the file and would be very pleased if
I could write to it as well.

Thanks in advance for the answers.

Erik Edlund
 
Huh, Should be a system.data thing, not a VB Express thing. ISAMS can an
ODBC driver but I find it faster and easier to use the Jet ISAM drivers.

I used Access to export the Biblio.mdb Authors table. Then opened VB
Express and started a new forms project.

Added a reference to System.Data.Dll and System.XML.dll.

Then added a datagridview, named it "grid1" and a button to the form.

At the top of the form I added Imports System.Data & Imports
System.Data.Oledb

In the button click I added:

Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\testarea;" & _
"Extended Properties=""dBase III""")

Dim ds As New DataSet
Dim da As New OleDbDataAdapter("Select * from Authors", cn)
Try
cn.Open()
da.Fill(ds)
grid1.DataSource = ds.Tables(0)
Catch ex As Exception
MsgBox(ex.ToString)
End Try

And there it was. Remember that for xbase files the folder where the files
are is the "Database" so in the above, my dbf and ndx files are in the
folder "C:\testarea" and the "Tables" are the dbf files themselves. Also
remember that the ISAM type name has to be exact in the connection string so
it's "dBase III" (with a space) for dbase 3, dBase IV for 4 and so on.

Hope that helps.

Robert Smith
Kirkland, WA
www.smithvoice.com
 
Thanks Robert!

Your advice made all the difference. But I really
don't see why Microsoft think that I should
understand that the Jet engine is the number one
choice for opening .dbf files.

I experienced further problems when I was trying
to add the Imports System.Data & Imports
System.Data.Oledb. I have used these in other
projects without problems, but in this case it was
impossible. Although I could see it in the Object
Browser I could not add it to the code without
generating an error message. The Intellisense(?)
wouldn't even show the .Data alternative to me.

I solved(?) the problem by placing a DataConnector
and a DataSet on my form, without using them at
all! Suddenly everything worked and strengthened
by this experience I removed them and it still worked!

best regards / Erik Edlund
 
Huh. That;'s interesting about the problems of adding the references in VB
Express. Maybe you ( or I?) are running different versions, there was the
original Express and then there was the October update .. and I don't know
if I updated mine or not.

In any case, you figured out how to get the reference and that means you're
ready to help out others who hit the problem - I will definitely remember
your trick, and I thank you for it. That's what brick walls are for :)

I use the Jet engine for ISAM connectivity because it's always just been
faster for me than dealing with ODBC, I don't know if it's Microsoft's "best
practice" route or not. The thing is that the Jet drivers are usually on
most machines by default... matter of fact, I did that test using an XP box
that has nothing on it but VB Express, Norton Antivirus, Flash MX and Flash
MX 2004 and I don't think that the Jet support came from Macromedia ;-)

Many of us know what it's like to support xBase these days but it sure is
better than that dark time when Redmond removed the xBase support from VB
completely (http://www.smithvoice.com/xbse2k.htm ), right?

All the best.

-smith
 
Back
Top