Re: Recordset & Sort

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



zamdrist@xxxxxxxxx wrote on 8 Mar 2006 07:35:51 -0800:

Was hoping to sort a recordset, returned by a stored procedure after
the fact. While the sort order the stored procedure works for me
otherwise, in this case I need to sort differently. This seemed hopeful
here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmscadoproperties.asp

However, Despite using a CursorLocation of adUseClient, depending on
where I place my sort property I get either no effect, or an error
message.

What is the exact text of the error message? I don't remember having a
problem with this before, but I do have a haib tof using ODBC providers.

If I set the sort poperty after the Execute method, I get a message
saying the current providor doesn't support the interfaces for sorting
and filtering. I tried using the OLEDB and native SQL Server providers,
and neither apparently support it, so says the error message.

The Sort property should be independent of the provider when using a client
side recordset.

If I place the Sort property before I execute the command procedure,
The sort property seems to have no effect.

Looking at your code, that is because after you set it you then set the
recordset object to the output of the command object, which resets the
recorset properties to those returned by the command object. This also
changes the client side cursor property. See below for suggested code
change.

Here is my code, keep in mind my connection is returned by yet another
function and otherwise works, thanks for any assistance:

Function ProcessApplicationDataSheet(sDocketNumber As String)

Dim iInventors As Integer 'Number of inventors user has selected
Dim adoConn As ADODB.Connection
Dim adoComm As New ADODB.Command
Dim adoRs As New ADODB.Recordset
Dim adoParam As New ADODB.Parameter

Set adoConn = ConnectSQLServer
adoComm.ActiveConnection = adoConn
adoComm.CommandText = "sp_UTL_PatFormGetInventorsByMatterID"
adoComm.CommandType = adCmdStoredProc

adoRs.CursorLocation = adUseClient '<--Here
adoRs.Sort = "QINVENTORRANK Asc" '<--Here

Set adoParam = adoComm.CreateParameter("@sMatterID", adVarChar,
adParamInput, 15)
adoComm.Parameters.Append adoParam
adoParam.Value = sDocketNumber

Set adoRs = adoComm.Execute

This causes the cursorlocation and sort to be reset! Try this instead:

adoRs.Open adoComm

As the adoRs object is no longer being reset, it will retain the sort and
cursor location properties from above.

Do While Not adoRs.EOF
Debug.Print adoRs.Fields(0).Value
adoRs.MoveNext
Loop

Set adoParam = Nothing
Set adoComm = Nothing
Set adoRs = Nothing

End Function

The change above should hopefully fix your problem.

Dan


.



Relevant Pages

  • Recordset & Sort
    ... Was hoping to sort a recordset, returned by a stored procedure after ... Dim adoConn As ADODB.Connection ... Set adoParam = adoComm.CreateParameter("@sMatterID", adVarChar, ...
    (microsoft.public.data.ado)
  • Re: Newbee help
    ... > to make pivot items visible, you need to set the sort property for the ... > Sub PivotShowItemResetSort() ... > Dim pt As PivotTable ...
    (microsoft.public.excel.programming)
  • Sorting A DataTable
    ... I've been looking around for ways to sort the rows in a DataTable, and everything seems to point to just changing the Sort property on that DataTable's DefaultView property. ... That's all well and good for viewing it sorted, but I need it to actually _be_ sorted, and testing seems to show that the view doesn't do the trick. ... Or am I going to have to write a sorting algorithm to do this? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: dymanicly sort a record set with a datagrid sortcommand
    ... It should just set the EditItemIndex to be the index the Edit event passes. ... My guess is that the sort is being set to the default value and the current index is selecting what ever is in it's place for edit. ... typically use a DataView on a DataTable and set its Sort property. ... using the component designer in vs.net i'm not sure how to do this, nor am i sure how to call the fill with the sort parameter. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Need help sorting a recordset using ADO
    ... No, you cannot sort it physically, using Sort property of the recordset. ... This is by-design to prevent expensive memory manipulation during sorting. ...
    (microsoft.public.vb.database.ado)