dataset - How to collect data from multiple databases and bind them in single datagridview? -


following code works single dataset when try dataset array sqldataadapter.fill() not work. trying connecting 6 different databases , run same sql query on them , collect data , show whole data 6 dbs in single datagridview. how it? thanks,

dataset[] myset = new dataset[6];    dataset finset = new dataset();                 (int j = 0; j <= 5; j++)                  myconnection.open();                  (int = 0; <= specrowcount - 2; i++)                 {                      cleandesc = datagridview2.rows[removalpointer].cells[1].value.tostring().replace("'", "''").trim();                     classname = datagridview2.rows[removalpointer].cells[0].value.tostring().trim();                      str = "use " + mydatabases[j] + " select top 1 x, y, z, t, h, f, d, " +                     "s, d, c, s, a, d, f, g, " +                     "s, f, a, dfrom tttt c=1 , a=1 , " +                     "d='" + cleandesc + "' , d= '" + d+ "'";                      myadapter = new sqldataadapter(str, myconnection);                      myadapter.fill(myset[j], "tttt");                       if (countrows != myset[j].tables["tttt"].rows.count)                     {                          mysb.appendline(datagridview2.rows[removalpointer].cells[1].value.tostring());                           datagridview2.rows.remove(datagridview2.rows[removalpointer]);                       }                     else                     {                          removalpointer++;                      }                        countrows = myset[j].tables["tttt"].rows.count;                      finset.merge(setarray[j]);                      datagridview1.datasource = finset.tables["tttt"];                   }                 myconnection.close();                  messagebox.show("con closed!");               } 

just based on code have shown us, looks problem fill myset[j] data adapter merge setarray[j] finset. data data adapter never makes finset.

another thing: i'm pretty sure code:

dataset[] myset = new dataset[6];  

... create array of datasets, array contain nulls every element. that's because you've created array, haven't created dataset objects fill it.

so code throw error, since you're attempting fill null:

myadapter.fill(myset[j], "tttt"); 

try this:

myset[j] = new dataset(); myadapter.fill(myset[j], "tttt"); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -