Sending a DataSet back to the database (C#)

  • Thread starter Thread starter Timothy Parez
  • Start date Start date
T

Timothy Parez

Hello,

Let's say I first fill a DataTable in a DataSet by using some
SQL command

"SELECT * FROM SomeTable"

Now I have another database,
and it has another table.

Now I want to send the DataSet I created from the first database
to this second database, but the table in the second database does not
have all the fields the first one does.

So I would like to send only a few fields from the DataTable in my
DataSet to the second table


Example

TABLE1
id
name
street
number
securityId
groupId
transactionId

TABLE2
id
name
transactionId

Of course the real example has a lot more fields.

I do SELECT * FROM TABLE1
put that in a DataTable
and now I want to send the rows in that DataTable to Table2
without the fields TABLE2 doesn't have.

How can I do this ?
 
Well I assume you have some default values in mind for the fields not
present in DataTable2.
Good.
Now you can specify these default values in the column objects in
DataTable2.
After simply add (DataTable2.Rows.Add(DataRows[]) or something like
that...) the rows from DataTable1 to DataTable2.

From there you can blast it all to the database using your favourite
DataAdapter.
 
But the Table where the values need to go has les fields then the
actuall number of fields in the DataTable.

I was thinking about using TableMapping,
but does Tablemapping support something to ignore certain fields

Like

TABLE1 TABLE2
-name ---> -name
-street ---> -street
-sid ---> -personalId
-securityNr --> IGNORE
-AccessLevel --> -accesslevel
-GroupId IGNORE

So that I can just send the data from TABLE1 to TABLE2
while it ignores the fields which are not in TABLE2

?


Well I assume you have some default values in mind for the fields not
present in DataTable2.
Good.
Now you can specify these default values in the column objects in
DataTable2.
After simply add (DataTable2.Rows.Add(DataRows[]) or something like
that...) the rows from DataTable1 to DataTable2.

From there you can blast it all to the database using your favourite
DataAdapter.

Timothy said:
Hello,

Let's say I first fill a DataTable in a DataSet by using some
SQL command

"SELECT * FROM SomeTable"

Now I have another database,
and it has another table.

Now I want to send the DataSet I created from the first database
to this second database, but the table in the second database does not
have all the fields the first one does.

So I would like to send only a few fields from the DataTable in my
DataSet to the second table


Example

TABLE1
id
name
street
number
securityId
groupId
transactionId

TABLE2
id
name
transactionId

Of course the real example has a lot more fields.

I do SELECT * FROM TABLE1
put that in a DataTable
and now I want to send the rows in that DataTable to Table2
without the fields TABLE2 doesn't have.

How can I do this ?
 
Back
Top