SelectCountMethod error - looking for parameters?

M

miky

Hi,
I'm trying to get custom gridview paging working and I'm getting the
following error:

"ObjectDataSource 'ObjectDataSource1' could not find a non-generic
method 'count' that has parameters: p_TableName, p_OrderBy, p_MaxRows,
p_PageNum, p_StartRowIndex."

I have a gridview associated to an ObjectDataSource and the
ObjectDataSource is declared in the aspx file as follows:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="LookupData"
SelectCountMethod="count" SelectMethod="selectMFPSData"
MaximumRowsParameterName="p_MaxRows"
SortParameterName="p_OrderBy" EnablePaging="True"
StartRowIndexParameterName="p_StartRowIndex">
<SelectParameters>
<asp:ControlParameter ControlID="lstMFPSTABLES"
Name="p_TableName" PropertyName="SelectedValue"
Type="String" />
<asp:parameter Name="p_OrderBy" Type="String" />
<asp:parameter Name="p_MaxRows" Type="Int32" />
<asp:parameter Name="p_PageNum" Type="Int32" />
<asp:parameter Name="p_StartRowIndex" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

The thing I don't understand is the "count" method the error refers to
is the method I've declared in the ObjectDataSource for the
SelectCountMethod property. The parameter list listed in the
declaration (in the <SelectParameters> hive) was generated when I
configured the ObjectDataSource to get a select parameter from a
control (a dropdownlist called lstMFPSTABLES).

So, a couple of questions:
1. Why is it erroring out on the count method, when the parameters are
meant for the select method?
2. Is it possible to parameterize the count method? This ability
would help in certain cases.


Thanks in advance for your help,

miky
 
M

Manu

Miky,

The ObjectDataSource will search for a SelectCount method with the
parameters specified in the SelectParameters collection. I know the
best possible design but...

Anyway, in your case, you are using paging and sorting so the
ObjectDataSource will automatically add the parameters for sorting and
paging later. If you don't specify the parameters in the ASPX you don't
need your SelectCount method to have those parameters. However, in your
case there is another parameter, p_PageNum that I don't know what are
you using for that will not be generated automatically by the
ObjectDataSource if you remove it.

Hope it helps,
Manuel Abadia
http://www.manuelabadia.com
 
M

miky

Manuel,
Thanks for that reply. It was the most direct information I've found
so far. So the SelectCountMethod AND the SelectMethod both look to the
SelectParameters? That seems odd to me. It actually works out for my
situation right now but it would rather make more sense to have two
sets of parameters, one for the SelectMethod and another for the
SelectCountMethod.

My situation works now because I specified the SelectMethod parameters
(SortParameterName, MaximumRowsParameterName,
StartRowIndexParameterName) in the ObjectDataSource declaration and
left the parameter that the SelectMethod and SelectCountMethod have in
common in the SelectParameters hive. But this is a specialized case...

Let me know if you have any further comments/clarifications. Thanks
again for your help.


miky
 
M

Manu

Miky,

As far as I can tell you, yes, they both look to the SelectParameters,
and yes, it's odd. If you think about it, the SelectCountMethod does
not make sense at all because the total item count could also be
retrieved by the SelectMethod. Also, keep in mind that you can add
attributes to the methods that will be consumed by the ObjectDataSource
with attributes like:

System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert)

and you know why? There is no DataObjectMethodType.SelectCount.

If you want to see a list of the problems and limitations of the
ObjectDataSource you can take a look here:

http://www.manuelabadia.com/blog/PermaLink,guid,32e83915-a503-403e-97c7-e20dcf2e0b7e.aspx

Hope it helps,
Manuel Abadia
http://www.manuelabadia.com
 
M

miky

Manuel,
Actually, the SelectCountMethod is needed in my case since I'm handling
paging at the database, not using the GridView's default mechanism.
Since this method only returns a designated page at a time the GridView
can't know the total records unless I tell it.

I'll look into your thoughts on attributes. I don't have a grasp of
them yet.

Thanks for your help (and the reference - I'll have to look into that
too)!


miky
 
M

Manu

Miky,

of course you need to retrieve the total row count from the database to
do decent paging. However, IMHO a better design would be to have an
output parameter in your select method instead of another method to
call. That way your SelectMethod can be static and everything done in
one call to the database server. With that logic split in two method
calls you need to have an instance variable to save the total row count
and return it in the SelectCountMethod or to perform another call to
the database in the SelectCountMethod (with most custom paging schemas
you can know the total row count where you do paging).

Manuel Abadia
http://www.manuelabadia.com
 
M

miky

I see. That makes sense. Thanks.




Miky,

of course you need to retrieve the total row count from the database to
do decent paging. However, IMHO a better design would be to have an
output parameter in your select method instead of another method to
call. That way your SelectMethod can be static and everything done in
one call to the database server. With that logic split in two method
calls you need to have an instance variable to save the total row count
and return it in the SelectCountMethod or to perform another call to
the database in the SelectCountMethod (with most custom paging schemas
you can know the total row count where you do paging).

Manuel Abadia
http://www.manuelabadia.com
 
Joined
Oct 22, 2008
Messages
1
Reaction score
0
Same Problem..Same Error...Help

Hi..

I m having a similar problem with objectdatasource & getting the same error.
I m trying to implement custom paging with objectdatasource & gridview.
I m posting the code for the SelectCount & Select Method

Public Function SelectCount(ByVal e As ObjectDataSourceSelectingEventArgs) As Integer
Return e.Arguments.TotalRowCount
End Function

Public Function [Select](ByVal UserID As Integer, ByVal WarehouseID As Integer, ByVal ItemID As Integer, ByVal startRowIndex As Integer, ByVal maximumRows As Integer, ByVal e As ObjectDataSourceSelectingEventArgs) As String
Dim arrParams(5) As SqlParameter
Dim objDataAccess As New clsDataAccess
' <summary>
' Populate the SqlParameter array
' </summary>
arrParams(0) = New SqlParameter("UserID", UserID)
arrParams(1) = New SqlParameter("WarehouseID", WarehouseID)
arrParams(2) = New SqlParameter("MyItemID", ItemID)
arrParams(3) = New SqlParameter("StartRow", startRowIndex)
arrParams(4) = New SqlParameter("PageSize", maximumRows)
arrParams(5) = New SqlParameter("NumResults", 0)

'e.Arguments.TotalRowCount = CInt("NumResults")

' <summary>
' Retrieve the data from database.
' </summary>
Return objDataAccess.ScalarValue_Get(WebConfigurationManager.AppSettings("Fulfillment_Server"), _
"Fulfillment", "InventoryHistory_Get", arrParams)

Array.Clear(arrParams, 0, 5)
End Function

Code for ObjectDataSource is

<asp:ObjectDataSource ID="objDSRecHistory"
SelectMethod="Select" EnablePaging="true"
TypeName="ObjDataSourceInventory"
SelectCountMethod="SelectCount"
OnSelecting="objDSRecHistory_Selecting"
StartRowIndexParameterName="startRowIndex"
MaximumRowsParameterName="maximumRows"
runat="server" >
</asp:ObjectDataSource>

I m getting the same error

ObjectDataSource 'objDSRecHistory' could not find a non-generic method 'SelectCount' that has parameters: UserID, WarehouseID, ItemID, startRowIndex, maximumRows, e.

Please Help.....
 
Joined
Apr 2, 2012
Messages
1
Reaction score
0
Both method, Select and Select count need the parameters. They (and you) need it because your going to restrict the set of all records taking into account that parameters.

Maybe your confusion is with PageSize wich is the second restriction.

An example without parameters:
records: {apples, pears, lemons}
selectcount 3

An example with parameters:
records: {apples, pears, lemons}
parameter: firstlatter = a
records: {apples}
I need firstlatter = a in selectcount to tell that only 1 is the totalcount of selected items starting with 'a'
selectcount 1 (without taking into account the parameter, selectcount will return 3
, and this is not consequent with the filter )

then you can do your "decent paging " but over the real count of records
 
Last edited:

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top