Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to speed these code,which is used to find matching record from two grid boths have 190000+ records
    primarykey
    data
    text
    <p>say i have two grid each contain 190000+ records ,named grid_A and grid_B,</p> <p>for every record in grid_A ,i want to find whether there is a same record in grid_B.</p> <p>grid_A and grid_B have same columns ,in my case,their columns is</p> <p>col1 col2 col3 col4</p> <p>and their datatype may be </p> <p>string datatime double</p> <p>by now,what i do is:</p> <p>for each row in grid_A,loop through all rows in grid_B,and compare the Four cols </p> <p>one by one.</p> <p>the code is shown blow:</p> <pre><code> //loop grid_A foreach (UltraGridRow row in ultraGrid1.Rows) { List&lt;object&gt; lo = new List&lt;object&gt;(); for (int i=0;i&lt;4;i++) //add col's value to ListA { lo.Add(row.Cells[i].Value); } //loop grid_B foreach (UltraGridRow rowDist in ultraGrid2.Rows) { List&lt;object&gt; loDist = new List&lt;object&gt;(); for (int ii=0;ii&lt;4;ii++) //add col's value to ListB { loDist.Add(rowDist.Cells[ii].Value); } if (CompareList(lo, loDist) == true) //compare two List { break; } } } // the function compare two List private bool CompareList(List&lt;object&gt; a, List&lt;object&gt; b) { //Assert a.count==b.count for (int i=0;i&lt;a.Count;i++) { if (!CompareObject(a[i], b[i])) return false; } return true; } // private bool CompareObject(object oa, object ob) { // object is string if (oa.GetType() == typeof(System.String)) { try { string strOb = Convert.ToString(ob); if (oa.ToString() == strOb) return true; else return false; } catch { return false; } } // object is datetime if (oa.GetType() == typeof(System.DateTime)) { try { DateTime dtOb = Convert.ToDateTime(ob); if ((DateTime)oa == dtOb) return true; else return false; } catch { return false; } } //object is double if (oa.GetType() == typeof(System.Double)) { try { double ddOb = Convert.ToDouble(ob); if ((double)oa == ddOb) return true; else return false; } catch { return false; } } return true; } </code></pre> <p>i know my compare way is too stupid,in fact,each loop circel cost 2.4 seconds, that is :190000 circels cost 130 hours,it looks so terrible, i heard it can use hash table to speed search performance,but i do not know how to use it. anyway,for each record in grid_A ,search all record in grid_B is unacceptable, so whatever help is appreciate.</p> <p>my grid's data is imported from excel,so it does not have sql database or table.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload