TableAdapter vs DataAdapter

S

s.bussing

Hi,

I was wondering when to use TableAdapters (TA) and when to use
DataAdapters (DA).


If I've got a typed dataset containing multiple related tables, I would
say use a DA to fill the dataset. Why should I use TA instead? I can
imagine situations where may be just one table from the dataset is
needed, in that case you might say, use a TA. I agree on that.


What about updating a typed dataset containing multiple related tables.
In that case I also would use a DA rather than TA's. I presume I will
need multiple TA's when updating multiple tables in this typed dataset
(i.e. added orderd and orderdetails in the typed dataset).

Conclusion: If I want to use just a few tables I would better fill the
tables using TA's and if I've got just one table to update I could also
use a TA. But when filling a dataset in one operation and when updating
multiple tables in a dataset I would better use a DA.

Is this correct?

P.S.: I will not use SQL in code, just SPROC's
 
C

Cor Ligthert [MVP]

Hi,

The DataAdapter is the abstract/mustinherit class from all DataAdapters. In
that are the SQLDataAdapter and the OleDBdataadapter.

The table adapters are strongly typed derived classes from those, they are
used with strongly typed datasets and have extra methods in them.

Telling when to use is hard to do, most regulars in this newsgroup avoid the
TableAdapters because that puts them in a cuirass, I see more newbies using
the TableAdapters.

No answer, but just a try to explain it.

Cor
 
S

s.bussing

Hi Cor,

thanks for sharing. I read all this in the ADO.NET 2.0 Core ref. I can
imagine using both, but I my opinion filling a whole dataset which
include multiple tables and relations can best be done using a DA. For
filling particulair tables, i.e. when you don't need a complete
dataset, TA is best to use.

I think I'll stick to that.

Further comments are welcom, always eager to learn.


Cor Ligthert [MVP] schreef:
 
W

William \(Bill\) Vaughn

The TableAdapter is designed to expose a strongly typed structure to manage
rowsets extracted from a specific Table or a JOIN. If you only access a
single table in the SELECT, the code-generators can also add the CRUD to
change the table.
The DataAdapter is designed to hold several rowsets from several queries (or
JOINs) and permit you to define artificial relationships between the
DataTable objects. It's updatable if the SelectCommand points to a single
table.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
Between now and Nov. 6th 2006 you can sign up for a substantial discount.
Look for the "Early Bird" discount checkbox on the registration form...
 
J

Jim Rand

Each TableAdapter contains a DataAdapter. Assuming your using an the XSD
designer, you can do something like this:

/*

*================================================================================

* Class Name: DSUserAcess

* Purpose: Customize dataset functionality

* Author: Jim Rand

* Date: 8/9/2006

*

* Revisions:

*================================================================================

*====================== Visual Source Safe
======================================

* $Author:: Jim $

* $Modtime:: 9/26/06 1:22p $

* $Revision:: 7 $

* $Workfile:: DSUserAccess.cs $

* $Archive:: /NET2005Development/MREIS.AgencyInfo/Datasets/DSUserAccess.cs $

*
===============================================================================

*/

namespace MREIS.AgencyInfo.Datasets

{

partial class DSUserAccess

{

private static readonly log4net.ILog _log =
log4net.LogManager.GetLogger(typeof(DSUserAccess));

private
System.Collections.Generic.List<System.Data.SqlClient.SqlDataAdapter>
_adapterList = new
System.Collections.Generic.List<System.Data.SqlClient.SqlDataAdapter>();

internal void Fill()

{

Helpers.DataAccessLayer.Fill((System.Data.DataSet)this, _adapterList);

} /* internal void Fill */

internal void PrepareDatasetForUse()

{

_adapterList.Add((new
DSUserAccessTableAdapters.NetApplicationTableAdapter()).daNetApplication);

_adapterList.Add((new
DSUserAccessTableAdapters.NetRoleTableAdapter()).daNetRole);

_adapterList.Add((new
DSUserAccessTableAdapters.NetFunctionTableAdapter()).daNetFunction);

_adapterList.Add((new
DSUserAccessTableAdapters.NetRoleCanDoTableAdapter()).daNetRoleCanDo);

_adapterList.Add((new
DSUserAccessTableAdapters.NetMemberTableAdapter()).daNetMember);

_adapterList.Add((new
DSUserAccessTableAdapters.NetRoleMemberTableAdapter()).daNetRoleMember);

Helpers.DataAccessLayer.FlipToProduction(_adapterList);

} /* internal void PrepareDatasetForUse */

internal void TearDown()

{

_adapterList.Clear();

_adapterList = null;

} /* internal void TearDown */

/* Update all tables in the backend */

internal void Update()

{

Helpers.DataAccessLayer.Update((System.Data.DataSet)this, _adapterList,
true, null);

} /* internal void Update */

} /* partial class DSUserAccess */

} /* namespace MREIS.AgencyInfo.Datasets */

namespace MREIS.AgencyInfo.Datasets.DSUserAccessTableAdapters

{

public partial class NetApplicationTableAdapter

{

public System.Data.SqlClient.SqlDataAdapter daNetApplication

{

get

{

this.Adapter.SelectCommand = this.CommandCollection[0];

return this.Adapter;

}

}

} /* public partial class NetApplicationTableAdapter */

public partial class NetRoleTableAdapter

{

public System.Data.SqlClient.SqlDataAdapter daNetRole

{

get

{

this.Adapter.SelectCommand = this.CommandCollection[0];

return this.Adapter;

}

}

} /* public partial class NetRoleTableAdapter */

public partial class NetRoleCanDoTableAdapter

{

public System.Data.SqlClient.SqlDataAdapter daNetRoleCanDo

{

get

{

this.Adapter.SelectCommand = this.CommandCollection[0];

return this.Adapter;

}

}

} /* public partial class NetRoleCanDoTableAdapter */

public partial class NetFunctionTableAdapter

{

public System.Data.SqlClient.SqlDataAdapter daNetFunction

{

get

{

this.Adapter.SelectCommand = this.CommandCollection[0];

return this.Adapter;

}

}

} /* public partial class NetFunctionTableAdapter */

public partial class NetRoleMemberTableAdapter

{

public System.Data.SqlClient.SqlDataAdapter daNetRoleMember

{

get

{

this.Adapter.SelectCommand = this.CommandCollection[0];

return this.Adapter;

}

}

} /* public partial class NetRoleMemberTableAdapter */

public partial class NetMemberTableAdapter

{

public System.Data.SqlClient.SqlDataAdapter daNetMember

{

get

{

this.Adapter.SelectCommand = this.CommandCollection[0];

return this.Adapter;

}

}

} /* public partial class NetMemberTableAdapter */

} /* namespace MREIS.AgencyInfo.Datasets.DSUserAccessTableAdapters */
 

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