Solved

Alter dBase IV table w/data loaded

Posted on 2000-04-20
8
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

751 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