• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

make sorting datagrid faster

Hi,

Is there anothery of sorting a datagrid column for faster results? if so please kindly give guidance.

Presently the sorting is taking so long since it would need to requrey fro mthe sql server.

Thanks.


         Sub Sort_Grid(sender As Object, e As DataGridSortCommandEventArgs)
         Dim SortExpression As String
         SortExpression = e.SortExpression.ToString()
         If SortMode = "Desc" Then
         SortMode = "Asc"
         SortExpression = SortExpression + " " + "Desc"
         Else
         SortMode = "Desc"
         End If
         Dim odataView as DataView = GenerateSource().DefaultView
         odataView.Sort=SortExpression
         datagrid1.DataSource=odataView
         datagrid1.DataBind()
         End Sub 'Sort_Grid

    Private Function GenerateSource() As DataTable
    Dim con As New SqlConnection("Server=.....")
    Dim cmd As SqlCommand = con.CreateCommand()
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "SP_operator_score_details_view"
    cmd.Parameters.Add(New SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", DataRowVersion.Current, Nothing))
    cmd.Parameters.Add("@operatorid",SqlDbType.int).Value = ddloperatorid.selecteditem.text
    cmd.Parameters.Add("@weekstartdate",SqlDbType.datetime).Value = ddlweek.selecteditem.text
    cmd.Parameters.Add("@qamonitorid",SqlDbType.int).Value = varqamonitorid
    Dim da As New SqlDataAdapter(cmd)
    Dim ds As New DataSet()
    da.Fill(ds,"DataSetName")
    Return ds.Tables("DataSetName")
    cmd.dispose
    cmd.parameters.clear
    con.close
    End function

0
EdwardPeter
Asked:
EdwardPeter
1 Solution
 
raterusCommented:
That is about the best way you are going to do it.  What were you hoping to do faster?
0
 
EdwardPeterAuthor Commented:
raterus,

if that's the case then question is answered :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now