Data Adapters - Conceptual Question

JesseH

Active member
Joined
Feb 9, 2006
Messages
42
Location
Sugar Land, TX
Programming Experience
10+
I had a customer master file and customer invoice file. The mission was to display the customer name, address, etc and the open invoices using a data grid. I was able to do it with no problem, but I had to set up two data adapters - one for the customer master and one for the invoice detail. Is this required or could I have done it in one? I noticed when I used the Adapter Query builder that the SQL was not what I needed, so I set up separately. Is there another way to do it?

Thanks for the help
 
Very good question. I'll try to explain the concept:

DataAdapter is the connection to the database - it is a link between the DataSet and the database. It basically tells the program where to go to get the data that fills the dataset and what criteria to use in order to get that data via the Select Command. Update, Insert and Delete command also are included.
A DataSet is a collection of DataTables. The tables are where the records are stored. Relationships such as your Master/Detail configuration are defined in the dataset to get two or more DataTables to function together.

Master/Detail - good for editing either table.
Your master/detail situation behaves like 2 seperate tables connected together in some manner. You are accessing and filling two seperate DataTables. The two DataTables have different selection criteria - Select Statements - each requires a DataAdapter. The two DataTables can be contained in the same DataSet (each DataAdapter can fill it's table in the DataSet) and the seperate tables will function together only when a Relation between the two is defined in the DataSet. One to many relationship on Customer ID Customer table ==> Invoice table.

Now for the "More than 1 way to skin a cat" information.
Single DataTable - more for display purposes
A single DataAdapter certainly could be used when the situation where a Join of two or more tables is desired. Say I have a customer ID in my invoice table. The ID doesn't tell me what I need to know - Customer 12345 is not the same as John Smith, South Bend, Indiana 46616. I want to join the invoice table with the customer table to display the stuff like Customer Name and Address. The DataAdapter selects records from the Invoice table and just adds Customer information to that table based on the ID Link. I have a singleDataAdapter and DataSet with a Single table in it. Each Invoice record just has Customer info added to it.

I Kind of got to rambling there, hope that helps.
 
Back
Top