Solved

Alter dBase IV table w/data loaded

Posted on 2000-04-20
8
405 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The canonical version of this article is on my web site here: http://iconoun.com/articles/collisions/ A companion presentation is available here: http://iconoun.com/articles/collisions/Unicode_Presentation.pdf
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 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

13 Experts available now in Live!

Get 1:1 Help Now