wittakarn
wittakarn

Reputation: 3162

CDX File not update after add a new recoed into DBF File

I would like to add a new record into dbf File(file name is STCRD.dbf). I added a new record by using visual studio 2017 > data connectionse as below picture.

enter image description here

After a new record is added, the cdx file, which is name STCRD.cdx, is not updated. I'm a newbie in visual foxpro. I still did not know after cdx file is changed, the dbf file should be changed as well or not. Can anyone point me to the correct way to add a new record into this kind of database?

I found some link that contain some information, but I cannot understand the answer about issueing the pack command.

Upvotes: 1

Views: 2363

Answers (2)

Dhugalmac
Dhugalmac

Reputation: 574

I'm a newbie in visual foxpro. I still did not know after cdx file is changed, the dbf file should be changed as well or not. Can anyone point me to the correct way to add a new record into this kind of database?

In VFP you create a Data Table (a DBF file) on which you can create an associated Index file (a CDX file).
Something like:

CREATE TABLE MyTable (field1 C(10), field2 M, Field3 D)
SELECT MyTable
INDEX ON field1 TAG firstfld  

Perhaps spending some time at the free, on-line VFP tutorials will help.
Free On-line VFP tutorials

Modifications to the Data Table (the DBF file - STCRD.dbf) will automatically 'trigger' the associated Index file (the CDX file) to update.

When you create an ODBC Connection you do so to the DBF file (STCRD.dbf), NOT the CDX file. Once your Data Table 'knows' about its associated Index file, CDX file behavior is 'automatic'. You don't work directly with the CDX file.

I guess that, for me, it is unclear what you are trying to accomplish. Get the ODBC Connection set up correctly and then explain clearly what it is that you are having trouble with.

Side Note: A DATABASE is a container (some are 'intelligent' like M$ SQL Server) and others are not (like a VFP Database), but they themselves are Not Data tables. The Data Table may or may not reside within a DATABASE, but it is the Data Table (not the DATABASE) in which data records 'live'.

Good Luck

Upvotes: 1

DRapp
DRapp

Reputation: 48169

You may want to check other posts about working with VFP and OleDb connections. The connection should point to the PATH that the files are located, not the individual file names / dbf / cdx / fpt.

So your connection string should point to just the

D:\Work\Sirichai\TNPSE

Then your select, insert, update, delete can just refer to the table and SHOULD work without issue...

select * from STCRD where ....

insert into STCRD ( fld1, fld2, fld3 ) values ( ?, ?, ? )

and parameterize the queries

Upvotes: 2

Related Questions