Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 23rd, 2003, 08:46 PM
Registered User
 
Join Date: Jun 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to connect .dbf file with ADO & DAO with code

Dear All members,
I want to make one application which add, edit & delete data to .dbf file. I want to know that How can I make connection with .dbf file using ADO & DAO.

Pl. any one know help me.

Thanx in advance for the help
 
Old July 25th, 2003, 02:16 AM
Authorized User
 
Join Date: Jul 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default

You can use UDL files to easily create & setup your connection strings, try this first:

1) Create a new text file on your pc, then rename the extension from *.txt to *.udl.
2) Open the file & you'll see a wizard type screen, select the 1st tab, then work your way through the screens & click the OK button when you've finished.
3) Rename the *.udl extension back into *.txt and open the file up. You should see in the very bottom line only the resulting connection string which has been built for you here.

Remove the ";Persist Security Info=False" part of the bottom line, as well as any lines above this from the file, then copy the final text you're left with into either of these samples:

 
Old July 25th, 2003, 02:19 AM
Authorized User
 
Join Date: Jul 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default

' ADO METHOD, NOTE YOU'LL NEED A REFERENCE SET FROM THE PROJECT
' MENU > REFERENCES SCREEN TO 'MICROSOFT ACTIVEX DATA OBJECT x.0
' OBJECT LIBRARY'. THE x WILL DEPEND ON YOUR INSTALLED VERSION OF
' ADO, BUT IF YOU CAN USE IT, GO WITH VERSION 2.6 IF IT'S THERE.

Private Sub Form_Load()
    Dim cnnADO As ADODB.Connection
    Set cnnADO = New ADODB.Connection

    cnnADO.ConnectionString = "TheUDLFileTextHere"
    cnnADO.CursorLocation = adUseClient
    cnnADO.Open

    ' Other work here ...

    Set cnnADO = Nothing
End Sub

 
Old July 25th, 2003, 02:22 AM
Authorized User
 
Join Date: Jul 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default

' DAO METHOD, NOTE YOU'LL NEED A REFERENCE SET FROM THE PROJECT
' MENU > REFERENCES SCREEN TO 'MICROSOFT DAO OBJECT x.x OBJECT
' LIBRARY'. THE x WILL DEPEND ON YOUR INSTALLED VERSION OF DAO.

Private Sub Form_Load()
    Dim dbDAO As DAO.Database
    Set dbDAO = New DAO.Database

    dbDAO.Connection = OpenDatabase("TheUDLFileTextHere")

    ' Other work here ...

    Set dbDAO = Nothing
End Sub

 
Old July 28th, 2003, 10:14 PM
Registered User
 
Join Date: Jul 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Probably should add a line to close the connection:
   cnnADO.close
I think?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening ,dbf file through ADO in VB6? vchell VB Databases Basics 2 September 11th, 2007 03:43 AM
Closing an ADO connection to a .DBF file tknnguyen Pro VB 6 2 July 25th, 2007 01:49 PM
How to connect to a dbf file using VBA? smartmani VB How-To 0 June 17th, 2005 04:39 PM
DAO & ADO knowledge76 Access VBA 1 January 24th, 2005 10:12 AM
DAo & ADO & connectionstring dr_morose Access VBA 5 November 17th, 2004 05:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.