0
我想尋求幫助,以什麼使這個代碼需要太長時間的過程:需要幫助,循環數據庫的時間太長
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,將其存儲到列表 ,並通過StoredProc將其插入數據庫。
哪部分代碼佔用了大量時間?根據你提供的例子,人們只能猜測'using'和'foreach'語句可能是瓶頸,因爲訪問數據庫和otehrone似乎做一些網絡操作,對吧? – nozzleman
循環數百萬次並不是一個好主意,試着找到一種方法來使用導入/導出嚮導從DBF導入數據。爲此也可能有一些免費的工具。 – FLICKER
@nozzleman - 先生,通常需要時間的部分是整個while循環過程。在1小時內,它只能將72936行添加到列表中 – mj5460