Optimizing binding

T

Tumurbaatar S.

All my datagrids need editing, deleting, sorting and paging. Datagrid's view
state is enabled,
but it is disabled it for each DataGridItem after binding. Also, I use
DataAdapter instead of
DataReader because the last one does not work with paging and sorting.
My typical data binding code looks like this:

string sql = "SELECT .... FROM tbl"; // a query does not contain ORDER BY
clause
SqlDataAdapter cmd = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
cmd.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
dv.Sort = sort; // a string like "some_fld DESC, another_fld ASC"
DataGrid.DataKeyField = "key_fld"; // specify a key field for update/delete
events
DataGrid.DataSource = dv;
DataGrid.DataBind();

And I thought, may be, using a sorting order directly in a SELECT statement
can improve a performance? I.e.:

string sql = "SELECT .... FROM tbl ORDER BY " + sort;

and removing following line:

dv.Sort = sort;

Also, any other ideas to increase performance of data binding without adding
a much of code?
 
E

Elton Wang

If you compare Sorting in sql query and in dataview, the first one should
have better performance.

However when user clicks any column header in the datagrid, you need to
conduct sorting again. If you save the query result (dataview) in Session
when in the beginning, you can get the dataview from Session and sort it. It
apparently has better performance than re-query DB.


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top