Solved

Alter dBase IV table w/data loaded

Posted on 2000-04-20
8
419 Views
Last Modified: 2013-12-20
I need to add a field to a dBase IV table that is already loaded with data.  I know the table structure can not be changed once the data is loaded, so I need a way to quickly transfer the data to a new table definition.  I have tried doing this the hard, ugly way - creating a new dBase file and copying over the data field by field and record by record.  It worked, but it is way too slow.  There must be a better way.

Is it possible to convert the .dbf file to another format (such as .mdb), then add and populate a new field, and finally convert the table back to a .dbf file?  Is there a better/faster way?
0
Comment
Question by:anasazi
8 Comments
 
LVL 1

Expert Comment

by:MT_MU
ID: 2736812
Since you have dBase IV....

Use <original_database>
Copy Struct Exte to Tmp.Dbf
Create <new_database> from Tmp.Dbf
Import From <original_database>


Then use Modi Struct to add the new fields you require.


0
 
LVL 1

Expert Comment

by:MT_MU
ID: 2736816
One correction....

instead of

Import from <original_database>

it should be

Append from <original_database>
0
 

Author Comment

by:anasazi
ID: 2738385
I don't actually have dBase IV - I'm just working with files that are in that format. Everything must be done within VB 6.0.
0
 
LVL 1

Expert Comment

by:MT_MU
ID: 2744066
Fair enough...since I attempted once - guess I should try again...

How about using a SQL Execute?

dbs.Execute "INSERT INTO newdb (field1, field2...) SELETE (field1,field2...) FROM olddb"

Concievably (if you are doing this repeatly) - you could generate the field names programaticaly.






0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 9

Expert Comment

by:cymbolic
ID: 2744980
If you are interested, I have a utility I built for modifying DBF files. Its a small, fast utility that runs in DOS.

Unfortunately, the only way you CAN add a field to these files is by copying over the dbf file.  Format for these .dbf files incorporates the format as a header portion in each record, including the actual physical record size.  If you change that size by adding a field, you must create a new header, and copy over each record to the new .dbf with the new record size.  There is not other "Magic" way to do it, since they are simply fixed length records stacked together.

cymbsys@aol.com
0
 

Expert Comment

by:ashwins
ID: 2746426
Dbase is the default standard for PC Database formats. So you can simply open the table in any package that reads data : Spreadsheets / Databases, etc. For eg. In excel you can open the file as a .dbf (Dbase IV files) make the changes you want and save the file back. It's that simple.

Also, there is no restriction on modifying tables with data in dbase. You only cannot change both the name and data-type at the same time.

Please back up your table before trying out anything, whether its VB / Excel / whatever.
0
 

Author Comment

by:anasazi
ID: 2748442
I do not want to use another package to work with these files - I want to do it all with code, within VB.  Also, I don't think you can change the structure of a dbase table once data has been loaded into it.  From within another package - maybe, with code in VB - no.  

I think that the comment posted by MT MU is the best suggestion.  I have tried using SQL to insert old DB data into new DB table structure and this works.  I would like to accept that comment as the answer - how do I do that?
0
 
LVL 1

Accepted Solution

by:
MT_MU earned 100 total points
ID: 2748684
Just accept my comment as an answer.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now