c# - SqlDependency Slow performance -
i use query notification of sqldependency
, here's scenario:
i have small table 100 records quite large data inside these records
here's code:
private void autoupdate() { sqldependency.stop(connectionstring); sqldependency.start(connectionstring); using (sqlconnection cn = new sqlconnection(connectionstring)) { using (sqlcommand cmd = cn.createcommand()) { cmd.commandtype = commandtype.text; cmd.commandtext = @"select [number], [creation date],[createdby], [approved] [dbo].[mytable] order number"; dt = new datatable(); cmd.notification = null; sqldependency dep = new sqldependency(cmd); dep.onchange += new onchangeeventhandler(dep_onchange); cn.open(); using (sqldatareader dr = cmd.executereader()) { dt.load(dr); } datagridview1.datasource = dt; } } }
and onchange
event use following code
private void dep_onchange(object sender, sqlnotificationeventargs e) { if (this.invokerequired) { datagridview1.begininvoke(new methodinvoker(autoupdate)); } else { autoupdate(); } sqldependency dep = sender sqldependency; dep.onchange -= new onchangeeventhandler(dep_onchange); }
i use cellvaluechanged
event trigger if user changes value in datagridview
the problem is: when user changes value of 1 cell, updates database , fires onchange
event cause reload datatable records
imagine user wants fill number
field value '0' first 50 record
the user press down arrow key 0 on keyboard continuously, , cause huge amount of data sent , received, because application receive datatable database after every press, , while trying experienced slow performance
is there better approach implement query notification?
is there way make onchange
event works on affected row? not whole table?
Comments
Post a Comment