Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update records in DBF file from VB 6.0?

Status
Not open for further replies.

VNDN

Programmer
Feb 28, 2003
27
US
Hello all,
Do you have any ideas of how to updating records in the
DBF file from vb, I have never work with dbf file extension before. Please guide me. Thanks much for your help.
 
vb5prgrmr?
How? do you have any examples?
 

Simplest way is to create an ODBC DSN to the directory of where the DBF's are (Settings>Control Panel>(Administrative Tasks)>Create ODBC Data Source, Using the MS VFP Driver, Using a "Free Table Directory") and then use the data form wizard to create you an example.

Good Luck

 
Here is a sample code. Let me know if you need any further help. Hope this helps.

Public gDBConnection As ADODB.Connection
Public rsCustomer As ADODB.Recordset


Set gDBConnection = New ADODB.Connection
Set mrsCustomer = New ADODB.Recordset

gsDBPath = "D:\data\test.dbc"
gDBConnection.ConnectionString = "Driver={Microsoft Visual FoxPro Driver};UID=;PWD=;SourceDB=" & gsDBPath & ";SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"
gDBConnection.CursorLocation = adUseClient
gDBConnection.Open

rsCustomer.Open "Select * from Customer where CustId = 1", gDBConnection, adOpenKeyset, adLockOptimistic, adCmdText
rsCustomer!LastName = tstLastName.txt
rsCustomer.Update

rsCustomer.Requery ' If you want to refresh a datagrid
 
rnathan,
Thanks for your sample code. It works but I ran into a date problem, I have a recordset that get the date field from the dbf file, but when my recordset returns, the date field changes to time and i dont know why it does that. any idea. Thanks CL
 
Set the date value to null if you really don't have any dates in the date field. And also in FoxPro, open the database, go to Tools->Options->Regional tab, for Date and Time, you may want to set Seconds check box to off.

Rita
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top