Strongly typed DataSets: Relation between DataTable and TableAdapter

  • Thread starter Thread starter Etienne-Louis Nicolet
  • Start date Start date
E

Etienne-Louis Nicolet

When creating a strongly typed DataSet using the "Add New DataSource..."
configuration wizzard a data table as well as a table adapter is created for
each database table.

Is there a way to get the DataTable a TableAdapter 'belongs' to by code?
Something like 'MyDataTable = MyTableAdapter.GetTable()' or so...? In case
would there be the opposite way, means getting the appropriate TableAdapter
from a given DataTable?

Many thanks for your help,
Etienne
 
A tableadapter can have different queries, insert and update methods for a
datatable.

It looks to me strange that you want to do it in an complete different way,
can you describe it a little bit more, by instance with code samples what
you want to do. (By the way, I seldon use the GetTable. I mostly use the
fill.

Cor
 
In general, unless you have change the default query, you use

MyDataTable = MyTableAdapter.GetData();

This produces an "every row in the table" DataSet. You can create a Get
method every time you create a new query. There is also a fill method, but
it works like this:

MyDataTable table = new MyDataTable():
MyTableAdapter.Fill(table);

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

*********************************************
| Think outside the box |
*********************************************
 
Sorry, this must have been a typical beginner's way to pose a question ;-)

Assuming I create a generic base base class like

' TDataRow refers to a DataRow in a strongly typed DataTable
Public MustInherit Class MyBusinessObjectBaseClass(Of TDataRow As DataRow)
Protected _databaseRecord As TDataRow
....
End Class

The objects derived from MyBusinessObjectBaseClass relate to a record in a
given database table and I'd like to put the logic to select, insert or
update the database records in the base class. Since the base class 'knows'
of what type my _databaseRecord is, isn't there a way to derive the
appropriate TableAdapter (and eventually the DataTable)?

If implemented in the derived object I would do someting like:

Dim ta As New MyDataSetTableAdapters.MyDataTableTableAdapter
ta.Update(_databaseRecord)

How, if possible, would I have to implement such methods in the base class?

Many thanks,
Etienne
 
Back
Top