I need progressbar with SQLBulkcopy

☆樱花仙子☆ 提交于 2019-12-11 02:23:56

问题


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();

    }

I really appreciate your responses.


回答1:


You need to handle the SqlBulkCopy.SqlRowsCopied event which

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

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



来源:https://stackoverflow.com/questions/38131088/i-need-progressbar-with-sqlbulkcopy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!