Example
of Updating a Foxpro Table Via ODBC Direct
Tested in VB6 SP1
This VB Tip is provided
courtesy of our friend Aslan. When
you're done here, be sure to check out her VBDelight web site for more delightful
info!
The problem: You are unable to update
a FoxPro table via DAO ODBC Direct. To
troubleshoot this, try the following sample: Note that this example uses the sample Foxpro table Labels.dbf.
1. Start a new Standard EXE project. Form1 is created by default.
2. Select References from the Project menu, check "Microsoft DAO 3.5 Object
Library", and then click OK.
3. Add the following code to code window for Form1:
Option Explicit
Private Sub Form_Load()
Dim db As Database
Dim rs As Recordset
Dim wk As Workspace
Dim myerror As Error
On Error GoTo trap
Set wk = DBEngine.CreateWorkspace("",
"", "", dbUseODBC)
wk.DefaultCursorDriver = dbUseODBC
' NOTE:
' A DSN entry has to be registered with the ODBC32 Manager in
' the control panel. In this case the DSN is called vfpdsn
Set db = wk.OpenDatabase("", False, False,
"ODBC;DSN=vfpdsn")
' NOTE:
' The name of the free table is "labels"
Set rs = db.OpenRecordset("Select * from labels", dbOpenDynaset, _
0, dbOptimistic)
rs.Edit
rs.Fields("name") = "This is a test"
rs.Update
rs.MoveNext
Exit Sub
trap:
MsgBox Errors.Count
For Each myerror In
Errors
MsgBox myerror.Number & " " &
myerror.Description
Next
End Sub
|