问题
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