Confused about the DataAdapter

B

Bob Weiner

I'm trying to learn/use ADO.Net and am puzzled by the DataAdapter.

It has a TableMappings property which is a collection of mappings from the
source into the DataSet. This implies that the DataAdapter can retrieve
many tables from a source and store each in a single DataSet.

But it only has a single SelectCommand so Fill() will only return single
result set.

I want to read 4 tables out of an access db. Do I need to create 4
DataAdapters to do it?


Confused
 
W

woutervu

Yes, you do. Think of a DataAdapter as a connection to a single table.
It provides the CRUD commands for you using the various ...Command
properties.
The DataAdapter contains a TableMappings property because it is
technically possible to return two resultsets from a single sql
command. Take the stored procedure below for instance.

Hence TableMappings..

Hope it helps,

Grtz, Wouter van Vugt
Info Support - The Netherlands
http://www.infosupport.com
http://blogs.infosupport.com/wouterv




Stored procedure:

CREATE PROCEDURE csp_Test

AS

SELECT * FROM Customers
SELECT * FROM Employees
 
S

Sahil Malik [MVP]

Fill can actually fill in multiple tables at the same time - as long as the
underlying datasource supports returning multiple resultsets.

Even if the underlying .net data provider/data source doesn't support
multiple results in one shot, you can still call Fill - 4 times - on the
very same data adapter by swapping the select command on it.

Alternatively, if you wanted to, you could fill the same dataset with 4
different data adapters, if you really wanted to.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
 
W

W.G. Ryan - MVP

Yes, you do. Think of a DataAdapter as a connection to a single table.
It provides the CRUD commands for you using the various ...Command
properties.

----Depending on the database, this isn't necessarily true. With Sql
Server, Oracle and most of the 'real' commercial RDBMS systems, batch
selects are available. That's actually what TableMappings are for (one of
the things anyway). So if the table name in one or more of the select
statements doesn't match what's in the query, you specify it (and if the
column names don't match, you can set them with columnmappings) and it will
match up. As long as the RDBMS supports batch commands, you can fill
multiple tables (among other thigns) in one command. This is actually a
really good way to do things in some intsances as it minimizes trips to the
server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top