約10万レコードのデータテーブルがあります。Datatable には、いくつかの整数値を含む複数の列があります。Total Count
これらの整数値を追加して、列とに書き込む必要がありますCommon Count
。次のコードを使用していますが、約 10 ~ 15 秒かかります。どうすれば効率的にこれを行うことができますか??
編集部分の開始
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@pudTowerList", SqlDbType.VarChar, 8000).Value = cellId;
cmd.Parameters.Add("@pudTowerCol", SqlDbType.VarChar, 8000).Value = cellIdCol;
sqlCon.Open();
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
SqlCon.Close();
cmd.Dispose();
編集部分終了
ここで、このデータブルを編集し、最後に gridview にバインドします
foreach (DataRow drow in dt.Rows)
{
int nTotalCount = 0;
int nCommonCount = 0;
for (int i = 2; i < nColumnCount; i++)
{
nTotalCount += int.Parse(drow[i].ToString());
if (int.Parse(drow[i].ToString()) != 0)
{
nCommonCount += 1;
}
}
drow["Total Count"] = nTotalCount; // On commenting this lines it runs fast
drow["Common Count"] = nCommonCount; // On commenting this lines it runs fast
}