what's the best way

J

John 3:16

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....
 
K

KJ

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.
 
J

John 3:16

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...
 
K

KJ

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.
 
S

Steve Mauldin

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
 
G

Guest

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...
 
J

John 3:16

Thanks KJ... I will discipline myself to you the dispose method whenenver
possible.
 
J

John 3:16

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.
 
J

John 3:16

Thanks Steve.
I will work with your example and try to understand how this works.
Thanks again,
Bob.
 
G

Guest

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.

If the data is being reused by multiple users, you can consider storing it
into cache. Otherwise... I would just dynamic query.
 

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

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,117
Latest member
Matilda564
Top