Updating a DataTable as opposed to a DataSet

N

Nick Zdunic

Hi,

I have loaded up some data into a DataTable as opposed to a
Dataset. The DataAdapter allows this.

I don't need all the associated stuff with the DataSet and
this is why I have chosen the DataTable.

However I'd like to update the changes to the DataTable to
the database it was loaded from. The DataAdapter can
update a dataset but not a datatable. How can I do this
then without having to resort to a manual procedure.

Does the version of the .NET framework I'm running make a
difference. I have 1.0. Does 1.1 support updating of
DataTables.

Thanks,

Nick Zdunic
 
D

David Browne

Nick Zdunic said:
Hi,

I have loaded up some data into a DataTable as opposed to a
Dataset. The DataAdapter allows this.

I don't need all the associated stuff with the DataSet and
this is why I have chosen the DataTable.

However I'd like to update the changes to the DataTable to
the database it was loaded from. The DataAdapter can
update a dataset but not a datatable. How can I do this
then without having to resort to a manual procedure.

Does the version of the .NET framework I'm running make a
difference. I have 1.0. Does 1.1 support updating of
DataTables.

Most DataAdapters (SQLDataAdapter, OleDbDataAdapter, OracleDataAdapter)
offer an overload to Update that accepts a DataTable. If your DataAdapter
does not, you can always add your table to a new empty DataSet.

David
 
N

Nick Zdunic

I've tried using a new Dataset but it generates an error - canot find
Table Mapping.

As I'm using a database independent Data Factory I'm using the
IDBDataApadtor interface to do the update. I want to avoid using
specific provider syntax. This only accepts the DataSet.

There must be some way of setting up the DataSet to take a table and
update to a database.
 
D

David Browne

Nick Zdunic said:
I've tried using a new Dataset but it generates an error - canot find
Table Mapping.

As I'm using a database independent Data Factory I'm using the
IDBDataApadtor interface to do the update. I want to avoid using
specific provider syntax. This only accepts the DataSet.

There must be some way of setting up the DataSet to take a table and
update to a database.

Ah Ha.

You can't support every dataadapter in the world.

Just downcast to the provider type and use the datatable override.
in VB
if typeof da is SQLDataAdapter then
directcast(da,SqlDataAdapter).update(dt)
elseif typeof da is OracleDataAdapter then
directcast(da,OracleDataAdapter).update(dt)
.. . .
end if

Or you could use reflection to see if the IdbDataAdapter has an update
method that takes a DataTable. In VB you can reflect like this:

directcast(da,Object).Update(dt)

David
 

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