[轉貼][心得]太多的DataView過濾效能不佳

看板C_Sharp (C#)作者 (tomex_ou)時間19年前 (2006/04/26 03:36), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
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
thx
04/26 10:26, 1F
文章代碼(AID): #14Jde-Hp (C_Sharp)
文章代碼(AID): #14Jde-Hp (C_Sharp)