.net - refresh data with sqldataadapter.fill - not seeing new data -
i have timer runs in background keep data updated datagridview object. timer calling sqldatadapter.fill fill local scoped dataset.
if go on sql server , delete row table call fill dataset not reflect change database.
if update value of non primary key field @ database , timer runs changes picked , shown in datagridview.
how need set sqldataadapter find when rows added or deleted other backend process?
this in form_load
if ds nothing ds = new dataset() end if try sqldataadapter = new sqlclient.sqldataadapter(selectquery, parentconnectionstring) sqldataadapter.missingschemaaction = missingschemaaction.addwithkey sqlcommandbuilder = new sqlclient.sqlcommandbuilder(sqldataadapter) sqldataadapter.fill(ds) mydata = ds.tables(0).defaultview catch ex exception exceptionhandler(ex) end try if mydata.table.rows.count > 0 bindingsource.datasource = mydata dgvsystemweightconfig.datasource = bindingsource updatelastupdatetime() end if
and refresh routine
public sub refreshdata() disableupdatetimer() try if dgvsystemweightconfig.iscurrentcellineditmode debug.writeline("tried refresh system weight data user had cell in edit mode") else debug.writeline("system weight - refreshing data") sqldataadapter.fill(ds, mydata.table.tablename) dgvsystemweightconfig.focus() updatelastupdatetime() end if catch ex exception exceptionhandler(ex) enableupdatetimer() end try end sub
don't assume sqldataadapter not have correct records. apparently datatable implements inotifypropertychanged not implement inotifycollectionchanged. bind observablecollection.
debug , count on ds.
bet source correct , ui control not picking changes.
for ui pick inserts , deletes need have source implements inotifycollectionchanged.
observablecollection implements inotifycollectionchanged.
datatable lot of stuff need replace.
need class or struct hold rows , need define columns.
autogeneratecolumns works datatable.
Comments
Post a Comment