[轉貼][心得]太多的DataView過濾效能不佳
I have a DataTable which contains 1545 rows. I have a method that returns a
DataTable of distinct rows based on one column. This table ends up with 386
rows.
I need to loop through the smaller table and filter a DataView based on each
row from this table.
This loops takes ~5 secs. Is there anyway to improve this?
DataTable dt = SelectDistinctValues(...); // returns a table with 386 rows
foreach (DataRow dr in dt.Rows)
{
dv.RowFilter = string.Format("value = '{0}'", dr[0].ToString() );
foreach (DataRowView drv in dv)
{
...
}
}
Answer:
Yes there is a much better way to do this.
Let me understand your problem first - You have two tables. One contains
distinct values but it was formed out of the first.
Instead of recreating a dataview everytime the user selects a row from the
distinct table, use the relation and use GetChildRows instead. That's MUCH
MUCH faster.
Reference:
http://0rz.net/cf1jx
GetChildRows/Relation sample:
http://www.c-sharpcorner.com/asp/Articles/MasterDetailDCHK.asp
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.20.171
推
04/26 10:26, , 1F
04/26 10:26, 1F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章