|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
what's the best wayHello...
I have a question related to performance. Being new to asp.net & vp programming, I put together a webform that displays columns of data in a datagrid. Users can sort by the header label. QUESTION: When they click to sort, I run a new stored procedure to return the resorted data... Should I only get the data once and query the disconnected dataset.. and if so .. can someone point me in the right direction. Thanks in advance.... Get the data once, and just use a DataView to sort, like so:
//(pseudo C#), in SortCommand event handler DataSet ds = GetMyDataSet(); // your function here DataView dv = new DataView (ds.Tables[0]); //first table v.Sort = "Clicked Column Name"; //column name of the table to sort on MyDataGrid.DataSource = dv; //set the sorted view as the data source to the datagrid MyDataGrid.DataBind(); // bind the grid to the view Note: Sort direction may also be changed by appending " ASC" or " DESC" to the v.Sort assigned value. Thanks KJ.
I will try to work through your suggestion. I have one more question if you don't mind... Is this the best..(fastest) way to retrive data into a dataset... Dim sTextBranchCounts As String = "dcc.dbo.afCount_Display" 'Stored Proc to return the Pre Processed Data Dim sConn As String = "SERVER=localhost;UID=*****;PASSWORD=*****;DATABASE=*****;" Dim dsBC As DataSet = New DataSet Dim cmdBC As SqlDataAdapter = New SqlDataAdapter(sTextBranchCounts, sConn) cmdBC.SelectCommand.CommandType = CommandType.StoredProcedure dsBC.Clear() cmdBC.Fill(dsBC, cmdBC.SelectCommand.ToString) Me.dgBranchCounts.DataSource = dsBC Me.dgFleetInspections.DataBind() Thanks in advance... Show quote "KJ" <n_o_s_p_a***@mail.com> wrote in message news:1137786200.823145.211030@f14g2000cwb.googlegroups.com... > Get the data once, and just use a DataView to sort, like so: > > //(pseudo C#), in SortCommand event handler > DataSet ds = GetMyDataSet(); // your function here > DataView dv = new DataView (ds.Tables[0]); //first table > v.Sort = "Clicked Column Name"; //column name of the table to sort on > MyDataGrid.DataSource = dv; //set the sorted view as the data source to > the datagrid > MyDataGrid.DataBind(); // bind the grid to the view > > Note: Sort direction may also be changed by appending " ASC" or " DESC" > to the v.Sort assigned value. > Your way of getting the job done looks fine. Note that the Framework is
quite flexible in that there are many ways to achive the same result. One thing to also get in the habit of is to call the Dispose method of any SqlDataAdapter, SqlCommand, SqlConnection, DataSet, or any other object you instantiate that provides a Dispose() method. This will ensure that your objects get cleaned up asap, releasing any unmanaged resources (such as COM objects) used by them under the hood. Thanks KJ... I will discipline myself to you the dispose method whenenver
possible. Show quote "KJ" <n_o_s_p_a***@mail.com> wrote in message news:1137793210.800523.290680@o13g2000cwo.googlegroups.com... > Your way of getting the job done looks fine. Note that the Framework is > quite flexible in that there are many ways to achive the same result. > > One thing to also get in the habit of is to call the Dispose method of > any SqlDataAdapter, SqlCommand, SqlConnection, DataSet, or any other > object you instantiate that provides a Dispose() method. > > This will ensure that your objects get cleaned up asap, releasing any > unmanaged resources (such as COM objects) used by them under the hood. > Bob,
I concur with KJ the Dataview is the way to go. I am attaching some code you may find useful. This is from a report from one of my websites that uses dataview to sort on grid clicks. NationalConferencetable is a datatable that in my code is stored in the application object but you can get your datatable from just about any persistent storage area Application, Session, Cache, etc.. I hope this helps you. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ReportDataGrid.DataSource = Application ("NationalConferencetable") ReportDataGrid.DataBind() End Sub 'sorting code to use headers to sort data. Private Sub ReportDataGrid_SortCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles ReportDataGrid.SortCommand Dim firstView As DataView = New DataView(Application ("NationalConferencetable")) firstView.Sort = e.SortExpression ReportDataGrid.DataSource = firstView ReportDataGrid.DataBind() End Sub Show quote "John 3:16" <bob***@tricoequipment.com> wrote in message news:u6p4wefHGHA.344@TK2MSFTNGP09.phx.gbl... > Hello... > I have a question related to performance. > Being new to asp.net & vp programming, I put together > a webform that displays columns of data in a datagrid. > Users can sort by the header label. > > QUESTION: When they click to sort, I run a new > stored procedure to return the resorted data... > > Should I only get the data once and query the > disconnected dataset.. and if so .. can someone > point me in the right direction. > > Thanks in advance.... > > Thanks Steve.
I will work with your example and try to understand how this works. Thanks again, Bob. Show quote "Steve Mauldin" <stevemaul***@hotmail.com> wrote in message news:u0mB%23wgHGHA.3752@TK2MSFTNGP11.phx.gbl... > Bob, > > I concur with KJ the Dataview is the way to go. I am attaching some code > you may find useful. This is from a report from one of my websites that > uses dataview to sort on grid clicks. NationalConferencetable is a > datatable that in my code is stored in the application object but you can > get your datatable from just about any persistent storage area > Application, > Session, Cache, etc.. I hope this helps you. > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > > ReportDataGrid.DataSource = Application ("NationalConferencetable") > > ReportDataGrid.DataBind() > > End Sub > > 'sorting code to use headers to sort data. > > Private Sub ReportDataGrid_SortCommand(ByVal source As System.Object, > ByVal > e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles > ReportDataGrid.SortCommand > > Dim firstView As DataView = New DataView(Application > ("NationalConferencetable")) > > firstView.Sort = e.SortExpression > > ReportDataGrid.DataSource = firstView > > ReportDataGrid.DataBind() > > End Sub > > > > > "John 3:16" <bob***@tricoequipment.com> wrote in message > news:u6p4wefHGHA.344@TK2MSFTNGP09.phx.gbl... >> Hello... >> I have a question related to performance. >> Being new to asp.net & vp programming, I put together >> a webform that displays columns of data in a datagrid. >> Users can sort by the header label. >> >> QUESTION: When they click to sort, I run a new >> stored procedure to return the resorted data... >> >> Should I only get the data once and query the >> disconnected dataset.. and if so .. can someone >> point me in the right direction. >> >> Thanks in advance.... >> >> > > "John 3:16" <bob***@tricoequipment.com> wrote in news:u6p4wefHGHA.344 @TK2MSFTNGP09.phx.gbl:> Should I only get the data once and query the Depends on how big your data set is... > disconnected dataset.. and if so .. can someone > point me in the right direction. -- Stan Kee (spamhoneypot@rogers.com) The biggest filtered set is just under 1,000 records.
It's currently taking 5-7 sec. to retrieve the data. I'd like to do this once when they open the webform and then when they sort, I'd like the data to be there already and just be able to change the sort on that data. Show quote "Spam Catcher" <spamhoneypot@rogers.com> wrote in message news:Xns9751AD43EF5AAusenethoneypotrogers@127.0.0.1... > "John 3:16" <bob***@tricoequipment.com> wrote in news:u6p4wefHGHA.344 > @TK2MSFTNGP09.phx.gbl: > >> Should I only get the data once and query the >> disconnected dataset.. and if so .. can someone >> point me in the right direction. > > Depends on how big your data set is... > > -- > Stan Kee (spamhoneypot@rogers.com) "John 3:16" <bob***@tricoequipment.com> wrote in news:u#4117CIGHA.3100 @tk2msftngp13.phx.gbl:> The biggest filtered set is just under 1,000 records. If the data is being reused by multiple users, you can consider storing it > It's currently taking 5-7 sec. to retrieve the data. > I'd like to do this once when they open the webform and > then when they sort, I'd like the data to be there already and > just be able to change the sort on that data. into cache. Otherwise... I would just dynamic query. -- Stan Kee (spamhoneypot@rogers.com) |
|||||||||||||||||||||||