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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Data Programmatically and Mapping Fields 1

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
Here is my problem. I have a program in VFP6 which imports data from one VFP table to another. The source table and the target table usually have the same fields. Once in a while the source table may have a new field.

The program works fine when the fields from the source table are mapped to the same fields from the target table.

However, in my dilemna I am mapping the fields as such:

SOURCE TARGET
Tel Tel
Lname Fname
Fname Lname
Addr Lname

Only Tel and Lname (both target fields) are being updated with the appropriate data. The Fname field is being populated with the Fname data and the Addr field is being populated with the Addr data.

Here is a snippit of the code:

For gcount = 1 to This.Parent.List3.listcount
srcfield = This.Page8.List3.list(gcount,1) && source
trgfield = This.Page8.List3.list(gcount,2) && target

m.&srcfield = custqry.&srcfield
m.&trgfield = m.&srcfield
Select TargetTable

For _nx = 1 to fcount()
sfield = "m."+field(_nx)
tfield = field(_nx)
Select Repres
Gather Memvar
EndFor Thanks,

Leo ;-)
 
create a table with the fields from both tables.
Append data from both tables into the new one

example
Use source
copy stru extended to dwg1
use target
copy stru extended to dwg2
use dwg1 exclu
append from dwg2
set deleted off
delete all
index on Field_name tag fn unique
set order to fn
recall all
set order to
pack
create dwg3 from dwg2
use dwg3
append from source
append from target
index as required
copy witrh cdx to target

Or try the Alter table command David W. Grewe
Dave@internationalbid.com
 
I'm afraid this is just a little more complex than that.

The user determines how many fields to import. The target table usually exists and may or may not already have data in it.

The trick is that the user may not always want to import the FirstName field into the FirstName field. In some cases, the user may want to import the FirstName field into the LastName field. This is where the import routines becomes very tricky.



Thanks,

Leo ;-)
 
Here is a thought, perhaps it can help. I am assuming that you are the person altering the source table, and creating the new field, or is it the program you've written?
Anyways, a little trick I use in some of my routines is to export the data out to a text file (SDF or Delim) from a source table, and import it into a destination table using the COPY FROM <filename> fields field1,2,3, etc. I find this save a lot of HD space and resource overhead.
 
OK, A long time ago (before the days of SQL), I wrote a routine to combine information from 2 tables.
The assumptions are that
1. there is a common key field
2. there was a cdx on the common field
3. both tables had the same field types (the field names could be different)

I have not run tis program in several years, but the code still looks like it will work.
Have at it if you want.
David W. Grewe
Dave@internationalbid.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top