Reputation: 63
foreach (string num in ld2.Keys)
{
double state;
int i;
for (i = 0; i < states.Count; i++)
{
cmd = mdb.getCommand("select value V " +
" from TAB_CHART_DATA " +
" where TIMESTAMP = (select max(TIMESTAMP) " +
" from TAB_CHART_DATA " +
" where chart_type= " + chart_type +
" and upper(upper(state)) = '" + states[i] + "' " +
" and CSIS_ID = " + CSISPID +
" and baselinecode like '" + num + "'" +
" ) " +
" and chart_type = " + chart_type +
" and upper(state) = '" + states[i] + "' " +
" and CSIS_ID = " + CSISPID +
" and baselinecode like '" + num + "'"
);
state = mdb.ExecSQLAndGetFirstInt(cmd);
}
}
This loop runs for more than 3000 times.
Upvotes: 0
Views: 578
Reputation: 498914
Fetch all rows in one query and loop over the result set in your code instead of opening cursors and killing the database.
Upvotes: 3