473,394 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

[VB.NET] Linking between multiple dbf files

I have 3 files that I want to pull information out of. All three files have a unique field and I want to pull bits and pieces from each file.

ex.
file1
customer number, first name, last name, phone

file2
customer number, last checkdate

file3
customer number, shipping address

what I want to export
first name, last name, phone, last checkdate, shipping address

I've already got the first part done, getting all the information out of file1 and it exports. Thanks for any help or pointing me in the right direction.
Oct 15 '08 #1
1 1052
mldisibio
190 Expert 100+
There are different ways of doing this, I will suggest one, but that does not mean it is the only way.

Since you say you can extract and export the data from the first file, then I will assume the issue is not how to open and read the files.

My suggestion is you create yourself a class representing what you want to export:
Expand|Select|Wrap|Line Numbers
  1. class Customer{
  2.  int customerNumber;
  3.  string firstName;
  4.  string lastName;
  5.  string phone;
  6.  DateTime lastCheckDate;
  7.  string shippingAddress;
  8.  
  9.  public Customer(int custNumber){
  10.    this.customerNumber = custNumber;
  11.  }
  12.  
  13.  public int CustomerNumber{
  14.    get{ return this.customerNumber;}
  15.  }
  16.  public string FirstName{
  17.    get{return this.firstName;}
  18.    set{this.firstName = value;}
  19.  }
  20. // etc for LastName, Phone, LastCheckDate Address
  21. }
  22.  
Now in your main process:
Expand|Select|Wrap|Line Numbers
  1. void Main(){
Create a List of Customers
Expand|Select|Wrap|Line Numbers
  1. List<Customer> myCustomerList = new List<Customer>();
Now when you read your first file, you extract the fields and create a customer instance for each record.
This assumes there is only one record per customer in each file. If there are duplicates, you will have some
decisions to make, but we won't complicate this initial idea with that yet.
Expand|Select|Wrap|Line Numbers
  1. // pseudocode: Open File. Read fields...
  2. // while ReadLine(){
  3. Customer tempCustomer = new Customer(Int32.Parse(field1));
  4. tempCustomer.LastName = field2;
  5. tempCustomer.FirstName = field3;
  6. // etc.
  7.  
  8. // Add the Customer to your list:
  9.  
  10. myCustomerList.Add(tempCustomer);
  11.  
  12. // } end read
  13.  
Now you have a list of customers, and two more files to read.
Essentially you are going to read the next file line for line, and for each line, retrieve the Customer object with the matching Id from your list.
Then you will udpdate the Customer object with the fields from that record in file2.
You will do the same for file3.

There are several ways to search for an object in a list. Here is one:

Create a method which calls the List.Find() method and returns the Customer that matches the Id you want.

This method will have to create a delegate to a method that returns true if a single Customer object has a matching Id:
Expand|Select|Wrap|Line Numbers
  1. private Customer FindByCustomerNumber(int customerNumber){
  2.  
  3.   // List.Find uses a delegate to a method which returns true or false
  4.   Predicate<Customer> findMatchingIdDelegate = 
  5.     delegate(Customer c) { return c.CustomerNumber == customerNumber; };
  6.  
  7.    return myCustomerList.Find(findMatchingIdDelegate);
  8.  
  9.   // Note: if no customer with that id is found, this method will return null, so make sure you deal with that case.
  10. }
  11.  
So, back to reading file2 and file3: you read each line (record), get the customer number, and then find the matching item in your List:
Expand|Select|Wrap|Line Numbers
  1. // while (ReadLine()){
  2. Customer existingCustomer = 
  3.   FindByCustomerNumber(Int32.Parse(currentIdField));
  4.  
  5. existingCustomer.ShippingAddress = field2;
  6.  
  7. // etc for each field in the current record of the current file
  8. // } // end ReadLine()
  9.  
Same for file3;

Now you have a list of Customer objects with all the fields you want.
Feed them into whatever export process you already have:

Expand|Select|Wrap|Line Numbers
  1. // pseudocode:
  2. foreach(Customer c in myCustomerList){
  3.   TextWriter.WriteLine(c.CustomerNumber.ToString() + c.LastName + c.FirstName + c.ShippingAddress); // etc etc
  4. }
  5.  
In a quick and dirty world, all of the above, except your customer class, would basically go into your Main method:
Expand|Select|Wrap|Line Numbers
  1. } // end Main
Oct 15 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting...
16
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
2
by: Nithya | last post by:
Hi, I encountered a problem when compiling multiple files with make file on solaris. The program uses a thrid party library file(.a) and when linking it to the program with -l option i get a error...
10
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
7
by: Salad | last post by:
I am converting an application from A97 to A2003. I have 2 tables created by another application as a Foxpro.dbf. The table has no index. The connect string in A97 is FoxPro...
10
kiseitai2
by: kiseitai2 | last post by:
Hi everyone. My problem is tha Dev-C++ compiles perfectly fine but it fails in the linking process. I receive the linker error "multiple definitions of"; howerver, I modified the names of the...
4
by: naveenmurthy | last post by:
Hello All, I have created a .mht file in following format. 1. The .mht file contains following htmls. a. MHTLinkingProblem.html b. Left.html c. Right.html d. Start.html
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.