Open DBF File in VB
Open DBF File in VB
Open DBF File in VB
Open DBF File in VB
Open DBF File in VB
Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB
Open DBF File in VB Open DBF File in VB
Open DBF File in VB
Go Back  Xtreme Visual Basic Talk > > > Open DBF File in VB


Reply
 
Thread Tools Display Modes
  #1  
Old 12-18-2003, 11:38 AM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default Open DBF File in VB


I need to figure out a way to open DBF Files in VB. I read somewhere about VB creating a temp mdb file and then opening the DBF table inside that DB, however I have no clue how to do this. Any suggestions.
Reply With Quote
  #2  
Old 12-18-2003, 11:45 AM
Flyguy's Avatar
FlyguyOpen DBF File in VB Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,162
Default

Are you using VB6 or VB.Net?

The file format for DBF is quite simple.
If you don't need anything advanced you can do some DBF reading yourself

For reading dbase files with VB6: http://www.xtremevbtalk.com/show...ighlight=dbase
Reply With Quote
  #3  
Old 12-18-2003, 11:45 AM
Optikal's Avatar
OptikalOpen DBF File in VB Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

You should be able to open the DBF directly with ADO.Net using either of the following connection string templates:

OLE DB:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\folder;Extended Properties=dBASE IV;User ID=Admin;Password="

ODBC:
"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=c:\mydbpath;"
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #4  
Old 12-18-2003, 11:52 AM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

Thanks for the quick reponse... here is what I have so far:

Code:
Public Function opendb() Dim MyConn As ADODB.Connection Set MyConn = New ADODB.Connection MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\sa\reserv.dbf;Extended Properties=dBASE IV;User ID=Admin;Password=" MyConn.Open End Function

But I keep getting this error:

run-time error '-2147467259 (80004005)':
c:\sa\reserv.dbf is not a valid path



now I know that is the correct path to the dbf, i even moved the file and tried c:\reserv.dbf.
Reply With Quote
  #5  
Old 12-18-2003, 11:53 AM
Optikal's Avatar
OptikalOpen DBF File in VB Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

try just C:\sa\ for the path, don't specify the actual filename.

Since this is VB6 it should not have been posted in the VB.Net forum, I'll get a mod to move it.
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #6  
Old 12-18-2003, 12:04 PM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

Quote:
Originally Posted by Optikal
try just C:\sa\ for the path, don't specify the actual filename.

Since this is VB6 it should not have been posted in the VB.Net forum, I'll get a mod to move it.




Oops.. i didnt notice it was in the vb.net forum.


so if i just use c:\sa\ then how do i specify the file i wish to open?
Reply With Quote
  #7  
Old 12-18-2003, 12:08 PM
Optikal's Avatar
OptikalOpen DBF File in VB Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

I've never used dBase/FoxPro before, but I assume the filename is somehow related to the data stored in it, possibly the filename matches the table name or something like that. If thats the case the OLE DB/ODBC driver should be able to determine which file to use to retrieve your data from based on the SQL statements you send it.
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #8  
Old 12-18-2003, 02:19 PM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

You are correct, it uses the file name for the table name.. I am at a stopping point.. I am just trying to pull anything out of the table and I keep getting an error, here is my code so far:


Code:
Public Function opendb() Set MyConn = New ADODB.Connection MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\sa;Extended Properties=dBASE IV;User ID=Admin;Password=" MyConn.Open End Function Public Function searchroute(stext As String) Dim sql As String sql = "SELECT Routeline from routing where tripnumber=118001" RS.Open sql, MyConn, adOpenForwardOnly, adLockReadOnly, adCmdText With RS Do While Not .EOF Main.Text1.AddItem RS("RouteLine") .MoveNext Loop End With End Function

Here is the error:

Run-time error '-21472179041' (80040e10)
No value given for one or more required parameters.
Reply With Quote
  #9  
Old 12-18-2003, 02:22 PM
Optikal's Avatar
OptikalOpen DBF File in VB Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

either Routeline or tripnumber is not a valid field name. Check for spelling mistakes in your code AND in your database schema.

Edit: actually, that may not be the case. What line does your error occur on?
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #10  
Old 12-18-2003, 02:24 PM
Flyguy's Avatar
FlyguyOpen DBF File in VB Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,162
Default

Also have a look at the link I posted to directly read the DBF file without using ADO
Reply With Quote
  #11  
Old 12-18-2003, 02:28 PM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

I am getting the error on this line:

Code:
RS.Open sql, MyConn, adOpenForwardOnly, adLockReadOnly, adCmdText

but i think it has to do with the SQL variable.
Reply With Quote
  #12  
Old 12-18-2003, 02:29 PM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

The table name, and both variable names are spelled correctly.
Reply With Quote
  #13  
Old 12-18-2003, 03:02 PM
Optikal's Avatar
OptikalOpen DBF File in VB Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

are you sure MyConn has been declared properly, and has been previously opened? and that routing is the appropriate table name
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #14  
Old 12-18-2003, 03:05 PM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

here is what i have for that:

Code:
Public MyConn As ADODB.Connection Public RS As New ADODB.Recordset
Reply With Quote
  #15  
Old 12-18-2003, 03:06 PM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

it has to be the SQL var.. because this works:

Code:
Public Function searchroute(stext As String) Dim sql As String sql = "SELECT * from routing" RS.Open sql, MyConn, adOpenForwardOnly, adLockReadOnly, adCmdText With RS Do While Not .EOF sql = RS("routeline") Main.List1.AddItem RS!RouteLine .MoveNext Loop End With End Function
Reply With Quote
  #16  
Old 12-18-2003, 03:08 PM
Optikal's Avatar
OptikalOpen DBF File in VB Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

so try

"SELECT routeline FROM routing"

if that works try

"SELECT * FROM routing WHERE tripnumber = 118001"

then you'll know which one is causing the problem.
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #17  
Old 12-18-2003, 03:13 PM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

Hmm... Neither of those work.... it doesnt seem to like the way we reference column names in the select statement because

SELECT * FROM routing

works fine.
Reply With Quote
  #18  
Old 12-18-2003, 03:15 PM
Optikal's Avatar
OptikalOpen DBF File in VB Optikal is offline
Codeaholic

Retired Leader
* Guru *
 
Join Date: Oct 2002
Location: Winnipeg, MB, Canada
Posts: 4,543
Default

try

"SELECT [routeline] FROM routing"

also try making sure the case is the same, I've never heard of a database being case-sensitive, but I suppose its possible
__________________
There are 10 types of people in this world, those that understand binary, and those that don't.
Reply With Quote
  #19  
Old 12-18-2003, 04:00 PM
Alvein's Avatar
Alvein Alvein is offline
Junior Contributor
 
Join Date: Aug 2002
Location: Iceland
Posts: 276
Default

I'm also gettin a problem with every SQL query I try.

"Index not found"

I only have to read one file (a DBF) and I don't have an index file for it. Furthermore, the Visual Data Manager can open the database (directory) and let me execute SQL code with no problems.

What can I do then??
Reply With Quote
  #20  
Old 12-19-2003, 08:32 AM
watkins watkins is offline
Centurion
 
Join Date: Jan 2002
Posts: 113
Default

Quote:
Originally Posted by Optikal
try

"SELECT [routeline] FROM routing"

also try making sure the case is the same, I've never heard of a database being case-sensitive, but I suppose its possible




I am still getting the same error after trying this... hmmmm. Is there anything we are missing as far as being able to select certain data based on certain criteria with these DBF's?


Flyguy, I would love to use your method, however I want to build support in later to write data into these dbf's, so I want everything to be consistent.

Last edited by watkins; 12-19-2003 at 08:55 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
File I/O GavinO Tutors' Corner 5 04-17-2013 01:18 PM
Makin a nice little program! Decontain Communications 3 04-11-2003 02:54 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Open DBF File in VB
Open DBF File in VB
Open DBF File in VB Open DBF File in VB
Open DBF File in VB
Open DBF File in VB
Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB Open DBF File in VB
Open DBF File in VB
Open DBF File in VB
 
Open DBF File in VB
Open DBF File in VB
 
-->