我有一个应用程序,其中用户上传了一个包含数百行的 Excel 文件,当他点击上传时,文件被转换为 aDataTable
并发送到数据库以由存储过程插入。上传花费了太多时间,我想显示已插入行数的进度。有没有办法做到这一点?
List<DataTable> tb = Helper.SplitTableToManyTables(FileTb, 50); // this is a function that split the Main dataTable to several Dt each have 50 rows
int importedRowsCount = 0;
for (int KLoop = 0; KLoop < tb.Count; KLoop++)
{
string[] ContctInfoCols = { "First Name", "Last Name", "Nickname", "Job Title", "Birthday", "Gender", "E-mail Address", "E-mail Address 2", "E-mail Address 3", "Web Page", "Mobile", "Mobile 2", "Mobile 3", "Home Phone", "Home Phone 2", "Business Phone", "Business Phone 2", "Other Phone", "Business Fax", "Home Fax", "Home Street", "Business Street", "Notes", "Company" };//the order of fields is very important
string contact = "";
DataTable resTb = new DataTable("ContactsTb");
resTb.Columns.Add("ContactInfo");
for (int iLoop = 0; iLoop < tb[KLoop].Rows.Count; iLoop++)
{
contact = ";";
DataRow dr = resTb.NewRow();
for (int jLoop = 0; jLoop < ContctInfoCols.Length; jLoop++)
{
if (ContctInfoCols[jLoop] != "" && tb[KLoop].Rows[iLoop][ContctInfoCols[jLoop]].ToString() != "")
contact += (jLoop + 1).ToString() + "~" + tb[KLoop].Rows[iLoop][ContctInfoCols[jLoop]].ToString().Replace("/", "") + ";";
}
dr["ContactInfo"] = contact;
resTb.Rows.Add(dr);
}
if (QueriesDataHelper.ImportContacts(resTb, int.Parse(TxtHiddenGroupId.Value), Session)) // here is the stored procedure call
{
importedRowsCount += resTb.Rows.Count;
var script = "DisplayProgressMsg(" + importedRowsCount + ")";
ScriptManager.RegisterStartupScript(this, GetType(), "MyScript", script, true); // here i am trying to display the currently inserted rows but it's not working
if (KLoop == tb.Count - 1)
MessageBox.Show(importedRowsCount.ToString()+" Contacts imported successfully");
}
//else
// MessageBox.Show("Sorry,an error occured during contacts upload.");
}
function DisplayProgressMsg(msg) {
alert(msg);
}