c# - DataBinding is very slow -
i using windows application c#. when bind data table datagridview gets slow , getting sql connection timeout error.
at same time data table has bulk records. how can solve problem?
code:
private void window_loaded(object sender, routedeventargs e) { con.statisticsenabled = true; con.open(); datatable dt = new datatable(); sqlcommand cmd = new sqlcommand("select * stktrn_table", con); sqldataadapter adp = new sqldataadapter(cmd); adp.fill(dt); griddisplay.itemssource = dt.defaultview; } sqlcommand cmdvoid = new sqlcommand("select party_no, smas_rtno,convert(numeric(18,2),sum(smas_netamount)) amount salmas_table ctr_no=@tcounter , smas_cancel<>1 , smas_rtno<>0 , smas_billdate=@tdate group smas_rtno, party_no", con); cmdvoid.parameters.addwithvalue("@tdate", dpbilldate.selecteddate.value); cmdvoid.parameters.addwithvalue("@tcounter", tcounternonew); sqldataadapter adpvoid = new sqldataadapter(cmdvoid); adpvoid.fill(dtvoid);
this line
sqlcommand cmd = new sqlcommand("select * stktrn_table", con);
will problem. not select rows database, limit using top
select top 100 column1, column2, column3 stktrn_table
in general select *
bad practice.
or alternatively, implement paging rows loaded on demand rather upfront.
how query run within sql server management studio? should initial indicator of how long query return database.
you use stored procedure may give performance benefit on raw sql query.
Comments
Post a Comment