473,383 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How do I access a .dbf file?

Hi,

I want to acces a .dbf file with visual studio 2008 express edition, but it doesn't work.When I try to open the connection, i get the error message 'D:\temp\Mijn Documenten\SDT\SDT Klantentool\SDT Klantentool\akttxt.dbf' is no valid path', but I'm sure it's the right directory. The .dbf file is a dBase file, but i don't know which version (I tried III, IV, and 5.0) but always the same error message.

Here's the code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=D:\temp\Mijn Documenten\SDT\SDT Klantentool\SDT Klantentool\akttxt.dbf;Extended Properties=""dBASE IV;"";"
'Open the database
con.Open() 'Here the error comes up!

sql = "SELECT * FROM akttxt"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "AktTxt")
con.Close()
MaxRows = ds.Tables("AktTxt").Rows.Count
inc = -1
End Sub

Please can someone help me with this, it's been giving me headaches for days now! If you want I can send the 'akttxt.dbf' file to you.

best regards
Mar 12 '08 #1
2 3348
jamesd0142
469 256MB
try this function:

NOTE: IMPORTS SYSTEM.DATA.OLEDB

Expand|Select|Wrap|Line Numbers
  1. Try
  2.             '---- Imports System.Data.OleDb - At top! ----
  3.             '---Usage---
  4.             'Dim oDS As New System.Data.DataSet
  5.             'DBConn("c:\users\users.mdb", "select * from TBLUsers", oDS, DGV1, "table2")
  6.             '---------
  7.             Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strSource
  8.             Dim oConn As New System.Data.OleDb.OleDbConnection(StrConn)
  9.             Dim da As System.Data.OleDb.OleDbDataAdapter
  10.             da = New OleDbDataAdapter(strQuery, oConn)
  11.             da.Fill(dataset, tablename)
  12.             'can change DGV - to the name of your DataGrid
  13.             DGV.DataSource = dataset.Tables(tablename).DefaultView
  14.             DGV.Refresh()
  15.             da = Nothing
  16.             dataset = Nothing
  17.             oConn = Nothing
  18.         Catch
  19.             MsgBox("Did not execute correctly")
  20.         End Try
  21.  
usage:

Expand|Select|Wrap|Line Numbers
  1. Dim oDS As New System.Data.DataSet
  2.         DBConn("c:\users\users.mdb", "select * from TBLUsers", oDS, DGV1, "table1")
  3.  
Mar 12 '08 #2
pureenhanoi
175 100+
Hi,

I want to acces a .dbf file with visual studio 2008 express edition, but it doesn't work.When I try to open the connection, i get the error message 'D:\temp\Mijn Documenten\SDT\SDT Klantentool\SDT Klantentool\akttxt.dbf' is no valid path', but I'm sure it's the right directory. The .dbf file is a dBase file, but i don't know which version (I tried III, IV, and 5.0) but always the same error message.

Here's the code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=D:\temp\Mijn Documenten\SDT\SDT Klantentool\SDT Klantentool\akttxt.dbf;Extended Properties=""dBASE IV;"";"
'Open the database
con.Open() 'Here the error comes up!

sql = "SELECT * FROM akttxt"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "AktTxt")
con.Close()
MaxRows = ds.Tables("AktTxt").Rows.Count
inc = -1
End Sub

Please can someone help me with this, it's been giving me headaches for days now! If you want I can send the 'akttxt.dbf' file to you.

best regards
I think you better create an ODBC DataSource, an point it to your DBF file
To Create ODBC DataSource:
Open Control Panel > Administrative Tools > ODBC DataSource
On the System DSN tab, click Add
Select "Driver do Mircosoft dBase" driver, and then Finish
Now, name the datasource is AKTTXT, select the right version for dBase file (you can change version latter if it does not correct)
Uncheck the "Use current Directory", and click "Select Directory" to select the folder that containing your dBase file. Finally, click Ok to complete

In VB project, simply use
con.ConnectionString ="AKTTXT"
con.Open

That "AKTTXT" is Datasource name you've made above
If it does not work correctly, try Change dBase version by edit AKTTXT DataSource
With ODBC Data Source, you can access more than one DBF file. Each file is now a Table (like table in MS-Access). File name is the table name (ofcoz, table name have no extension). If you want access another DBF file, simply move this DBF file to the Directory you've selected in ODBC DataSource
Mar 13 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: *no spam* | last post by:
I want to move my Access 2K database into MSDE. The Access Upsizing Wizard crashes (a known bug wi A2K), so I'm using the following suggested method: Access --> New --> Project (Existing...
2
by: bbxrider | last post by:
is there no other way to use access(.mdb) across the internet?? (than vpn or worse yet terminal services) i'm trying to write to a mdb on my organization win2k server from my webhost redhat...
10
by: MHenry | last post by:
Hi, We were going merrily along for 6 years using this database to record all client checks that came into our office, including information about what the checks were for. Suddenly, network...
8
by: John Baker | last post by:
Hi: I am URGENTLY in need of some book or web site OR tool that will help me integrate a relatively simple access application into a web page or pages. This is a time recording system (by...
0
by: bettervssremoting | last post by:
To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool including SourceOffSite, SourceAnyWhere and VSS Remoting This article makes a detailed...
4
by: bbdobuddy | last post by:
Hi, How do I open a Microsoft Access 2003 form from Visual Basic.net Thanks in advance bbdobuddy
70
by: lgbjr | last post by:
Hello All, I've been developing a VB.NET app that requires the use of a DB. Up to now, I've been using Access. It's a bit slow, but everything works. I'm at a point now where I need to decide if...
8
by: carriolan | last post by:
Hi I have an MS Access based application almost ready for distribution to the public and I find that even though I have compiled it into an MDE file, tables and queries can still be be imported if...
49
by: Mell via AccessMonster.com | last post by:
I created databases on Access 2003 and I want to deploy them to users. My code was also done using 2003. If they have Ms Access 2000 or higher, will they be able to use these dbs with all code,...
17
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.