Merge dataset into identical table?

C

Chris Ashley

Hi there,

If i have a dataset which has a datatable which has fields matching an
existing SQL Server DB Table exactly, is there an easy way to merge all
the records from the datatable into my SQL table without having to
write a stored procedure or SQL insert statement?

Cheers,

Chris
 
W

W.G. Ryan - MVP

No - but if the table has a key what you can do is create two dataadapter
and set the AcceptChangesDuringFill property of the first adapter to false.
Then you can use a CommandBuilder for the second, and call Update on it
passing in the newly filled dataset to it. The commandbuilder will
effectively write the Insert statement, but short of that, there's no
automagic way. Obviosuly you could use DTS to move data around, but not
between a System.Data.DataTable natively.
 
C

Chris Ashley

W.G. Ryan - MVP said:
No - but if the table has a key what you can do is create two dataadapter
and set the AcceptChangesDuringFill property of the first adapter to false.
Then you can use a CommandBuilder for the second, and call Update on it
passing in the newly filled dataset to it. The commandbuilder will
effectively write the Insert statement, but short of that, there's no
automagic way. Obviosuly you could use DTS to move data around, but not
between a System.Data.DataTable natively.

Thanks for that - wouldn't have thought of doing it that way myself.
Seems to work a charm!

Chris
 

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