与class和insert比较数据库表 [英] Compare with database table with class and insert

查看:89
本文介绍了与class和insert比较数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在表中有大量数据我想要添加/更新到表中。



我为新添加的数据创建了类列表。



现在要插入类数据可能是所有值都需要更新插入的其余部分。



哪种方法最好?



我尝试了什么:



我尝试使用for循环的基本方法,但我认为它不是优化方式。

I have an huge data in a table now i want to add/update to the table.

I created the list of class for newly added data.

now want to insert the class data may be all some value need to be update rest of the inserted.

Which is the best approach?

What I have tried:

I try to basic approach using for loop but i think it not optimize way.

推荐答案

由于您没有指定WHICH数据库,因此难以为您提供硬性和快速的解决方案。一般来说,您有三种方式:



1.将所有数据插入并更新到数据库中 - 您需要存储过程与表(在SQL Server中)或XML参数 - 这样,所有处理都在数据库中完成 - SQL Server可以将XML视为一个表,因此您可以批量插入/更新。这就是我在2010年的方式。



2.使用.NET特定类SqlBulkInsert(或数据库的等价物)发送数据(你必须分开)什么是插入和什么是发送前的更新) - 从不使用,所以我不能提供任何细节



3.逐行发送数据,你可以决定代码(通过RowState.Added,RowState.Modified属性)或在数据库中。如果是前者,则需要两个存储过程(或查询),一个用于插入,另一个用于更新)。或者您可以将数据发送到存储过程并在那里决定。 DB2有一个很好的命令MERGE可以同时执行两个操作:)



我希望这有点帮助。祝你好运
Since you didn't specify WHICH database its hard to give you hard and fast solution. In general, you have three ways:

1. Send all of the data for insert and update into the database - you need stored procedure with table (in SQL Server) or XML parameter - this way, all your processing is done in the database - SQL Server can treat XML as a table so you have bulk insert / update. This is the way I did it in 2010.

2. Use .NET specific classes SqlBulkInsert (or equivalents for your database) to send the data (you have to separate what is insert and what is update before sending) - NEVER USED, so I cannot provide any details

3. Send the data row by row, you can either decide in code (via RowState.Added, RowState.Modified properties) or in the database. If former, you need two stored procedures (or queries), one for insert, second for update). Or you can send the data into stored procedure and decide there. DB2 has a nice command MERGE which can do both at the same time :)

I hope this helps somewhat. Good luck


这篇关于与class和insert比较数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆