Fastest way of filling a combobox from a datatable in VB.Net -
the data table in following code filled 7500-+ records. loads server. problem takes while loop through data rows add them combo box. there alternative way of setting data source of combo box or way of speeding process up?
dim dtcolours new datatable dim dacolours new sqldataadapter dim integer connecttosql() dacolours = new sqldataadapter("select distinct rtrim(upper(colour)) colour invstockcolour inuse = 1 order colour", dbsql) dacolours.fill(dtcolours) = 0 dtcolours.rows.count - 1 cbocolours.items.add(dtcolours.rows(i).item(0).tostring) next dbsql.close()
the fasted way use addrange
method instead of using add
, like:
dim items = dtcolours.asenumerable().select(function(d) directcast(d(0).tostring(), object)).toarray() cbocolours.items.addrange(items)
i did simple check , using addrange
~3x faster using add
.
of course allocating array , filling for
loop milliseconds faster using linq.
Comments
Post a Comment