我想请求帮助,说明这段代码需要花费太长时间来处理:
using (OleDbDataReader dr = command.ExecuteReader()){
while (dr.Read())
{
count += 1;
if (Convert.ToDecimal(dr["AMOUNT"]) == Convert.ToDecimal(0.00) &&
Convert.ToDecimal(dr["PENALTY"]) == Convert.ToDecimal(0.00) && Convert.ToDecimal(dr["DEPDIV"]) == Convert.ToDecimal(0.00))
{
//Cancel Upload and let user check is .DTLS contains Amount
ViewBag.Message = "UPLOADING CANCELLED!! : .DTLS file does not contain any amount for the Following Fields :"
+ "AMOUNT UNPAID, "
+ "PENALTY "
+ "DEPDIV "
+ "PLEASE CHECK INGRES SETTING FOR MONEY FORMAT(REQUIRED MONEY FORMAT IS : II_MONEY_FORMAT=L:á"
+ "THEN REDOWNLOAD THE .MAST and DTLS FILE from the DELINQUENT EMPLOYERS EXTRACTION UTILITY BEFORE UPLOADING";
return View();
}
else
{
string Acctno, EyerID, Percov;
decimal Amount, Penalty, DepDiv;
EyerID = dr["EYERID"].ToString().Trim();
Percov = dr["PERCOV"].ToString().Trim();
Amount = Convert.ToDecimal(dr["AMOUNT"]);
Penalty = Convert.ToDecimal(dr["PENALTY"]);
DepDiv = Convert.ToDecimal(dr["DEPDIV"]);
Acctno = SaveUpdateTransMaster.spRetrieveAcctNo(EyerID, brid, "MCDEL", Convert.ToDateTime(currCutoff));
ListLedger.Add(new TransLedger
{
EyerID = EyerID,
AcctNo = Acctno,
Percov = Percov,
AmtDue = Amount,
Penalty = Penalty,
DepDiv = DepDiv,
});
}
}
}
"MCDEL");
}
foreach (var row in ListLedger)
{
SaveUpdateTransMaster.spUploadTransLedgerCA(row.AcctNo, row.EyerID,
currCutoff, row.Percov,Convert.ToDecimal(row.AmtDue), Convert.ToDecimal(row.Penalty),
Convert.ToDecimal(row.DepDiv), brid, "MCDEL");
}
以下是我的情景:
我通常会将数百万行读取到FoxPRO DBF,并将其存储到List中 并循环它通过StoredProc将其插入DB。
答案 0 :(得分:0)
您似乎正在复制某些代码。当您创建每一行时,您将Amount,Penalty和DepDiv转换为小数,然后在上传它们时再次将这些字段转换为十进制。此外,您在if语句的条件部分计算它们。您应该在if语句之前计算每一行的值,以减少一些代码重复并节省时间。即使你每行只节省一毫秒,那么每百万行的时间差不多是17分钟。
但是,正如Alan B建议的那样,也许您可以发布Foxpro查询的代码,我们可以查看它以改进速度和/或数据格式。可以更改查询以输出可以直接导入SQL Server的内容,例如逗号或制表符分隔文件。