我想寻求帮助,了解是什么让这段代码需要很长时间来处理:
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,并将其存储到列表中并循环它通过 StorageProc 将其插入数据库。
看起来您正在复制一些代码。创建每一行时,会将"金额"、"罚金"和"DepDiv"转换为小数,然后在上载它们时再次将这些字段转换为十进制。此外,您正在 if 语句的条件部分中计算它们。您可能应该计算 if 语句之前每一行的值,以减少一些代码重复并节省时间。即使您每行只节省一毫秒,也几乎是每百万行 17 分钟。
但是,正如Alan B所建议的那样,也许您可以发布Foxpro查询的代码,我们可以查看速度和/或数据格式的改进。也可以更改查询以输出可以直接导入到 SQL Server 的内容,例如逗号或制表符分隔的文件。