我的应用程序需要进度条.我正在通过文本文件将数据上传到 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 的进度条
发布评论