我需要带有 SQLBulkcopy 的进度条

编程入门 行业动态 更新时间:2024-10-14 20:21:32
本文介绍了我需要带有 SQLBulkcopy 的进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的应用程序需要进度条.我正在通过文本文件将数据上传到 SQL Server 中,但它需要很多时间,而且我使用了后台工作人员,但无法正常工作,所以我只需要知道有什么方法可以将进度条与 SQL 批量复制一起使用它告诉我插入了 2000 条记录?这是我的代码:

I need progress bar for my application. I am uploading data through text file into SQL Server but it takes a lot of time and also i used background worker for the same but that's not working properly so i just need to know is there any way i can use progress bar with SQL Bulk Copy and it tells me that's 2000 records inserted? Here is my code:

public void bulkinsert(string tablename, DataTable dt) { if (con.State == ConnectionState.Closed) { con.Open(); } SqlBulkCopy blkcopy = new SqlBulkCopy(con); blkcopy.DestinationTableName = tablename; blkcopy.BatchSize = dt.Rows.Count; blkcopy.BulkCopyTimeout = 1500; blkcopy.WriteToServer(dt); blkcopy.Close(); }

非常感谢您的回复.

推荐答案

您需要处理 SqlBulkCopy.SqlRowsCopied 事件其中

You need to handle the SqlBulkCopy.SqlRowsCopied event which

每次达到 NotifyAfter 指定的行数时发生财产已被处理.

Occurs every time that the number of rows specified by the NotifyAfter property have been processed.

我也会使用 Async Await 并使用 Progress 而不是后台工作者

I would also use Async Await and use a Progress<T> instead of a background worker

更多推荐

我需要带有 SQLBulkcopy 的进度条

本文发布于:2023-11-12 10:35:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581244.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进度条   SQLBulkcopy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!