简体   繁体   中英

How to Copy and Insert from c# DataSet to PostgreSQL DataBase with Npgsql?

I have an DataSet with (f example) two DataTables . My c# application fills up the data to DataTables of current DataSet. Also, I have a DataBase in PostgreSQL with the same two tables with the same columns. How I can Upsert ( ON CONFLICT DO NOTHIG ) full DataSet to my DataBase?

I know complicated way to do that with inserting each single row from DataTable to Postgresql Table, but maybe there are some cute, simple and fast way to insert whole DataSet to DataBase?

Also, How I can read the not empty DataBase to the empty DataSet with the same tables and tables' rows?

Thanks for your answer!

ON CONFLICT DO NOTHING (ie upsert) is a PostgreSQL-specific feature. As DataSet/DataTable are a general .NET feature and work with other databases, they will not generate upserts for you. You will have to write your own SQL to upsert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM