Updating a DataTable as opposed to a DataSet

  • Thread starter Thread starter Nick Zdunic
  • Start date Start date
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
 
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
 
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.
 
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
 
Back
Top