如何以快速的方式将数据从datagridview插入表中c# [英] How to insert data from datagridview to table in quickly manner c#

查看:100
本文介绍了如何以快速的方式将数据从datagridview插入表中c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在visual studio 2015窗体上工作 

I worked on visual studio 2015 windows form 

我有datagridview有超过5000条记录 

I have datagridview have more than 5000 record 

我的主要问题是如何插入5000条记录 快速地在桌子上一次

my main problem is how to insert 5000 record  on table at once by quickly way

我这样做花了太多时间花了4分钟

i do it by it take too much time take 4 minutes

以便快速完成这个过程方式 

so that how to do that process on quickly way 

推荐答案

您好,

如果将SQL-Server用于数据库,请参阅以下代码示例,两者都相同,一个是C#,一个是VB.NET

If using SQL-Server for a database see the following code samples, both are the same, one is C#, one VB.NET

C#代码示例

< a href ="https://code.msdn.microsoft.com/SQL-Server-bulk-insert-and-22b3c181?redir=0"> VB.NET代码示例。

两者都基于
MERGE

请注意,上述内容不适用于直接在行/单元格中输入数据的情况,而是用于使用DataTable加载DataGridView。您可以在DataGridView的行/单元格中加载数据,但是对于任何非字符串
的数据,需要进行强制转换,而强类型DataTable不需要在DataGridView中转换字段数据。

Please note the above is not for where you entered data directly into rows/cells but instead for loading the DataGridView with a DataTable. You can take data loaded in rows/cells of a DataGridView yet then a cast is needed for any data that is not a string while a strong typed DataTable needs no casting of field data in the DataGridView.

最后,MERGE可以使用'match'子句在一个语句中处理INSERTS / UPDATES / REMOVAL。

Lastly MERGE can handle INSERTS/UPDATES/REMOVAL in one statement using the 'match' clause.

最好在项目的.sql文件中编写SQL(创建一个文本文件,将.txt更改为.sql)例如

Best to write the SQL in a .sql file in your project (create a text file, change .txt to .sql) e.g.

然后在代码中编写SQL并设置命令对象的CommandText(最好查看代码示例)

Then write your SQL in code and set the CommandText of your command object (best to see the code sample)

对于5000条记录而言,MERGE应该少于10秒10个字段,更多字段,添加更多秒但从不分钟,除非数据库表未规范化。

The MERGE should take less than ten seconds for 5,000 records with say less than 10 fields, more fields, add more seconds but never minutes unless the database tables are not normalized.

MS-Access数据库没有MERGE。

There is no MERGE for MS-Access databases.


这篇关于如何以快速的方式将数据从datagridview插入表中c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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