Home
 Index > ASP.NET Web Applications > ObjectDataSource 'XXX' could not find a non-gen...

ASP.NET Web Applications:  Databinding , GridView , ObjectDataSource

ObjectDataSource 'XXX' could not find a non-generic method 'XXX' that has parameters: XXX, XXX, XXX

Error occurs when binding a data control such as a GridView with an ObjectDataSource.

Added on 29 Jun 2008

Scenarios:

Scenario Summary:
When binding a GridView to an inline ObjectDataSource, the above error is thrown.
Scenario Details:
The error is thrown despite the fact that  the ObjectDataSource's custom SelectMethod and TypeName properties map to an existing Method and Class within the same assembly.

SQL:
ALTER  PROCEDURE [dbo].[usp_MyProc]
(
    
@PrimaryKey int = 0,
    
@SearchString varchar(50) = '',
    
@IsEnabled bit = 0
)
AS
....

ASPX:
<asp:ObjectDataSource  ID="ObjectDataSource1" runat="server" DeleteMethod="DeleteSP" SelectMethod="SelectSP"  TypeName="MY_DAL"></asp:ObjectDataSource>

ASPX.VB (Code Behind)
    Protected Sub ObjectDataSource1_Selecting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.ObjectDataSourceSelectingEventArgs) Handles ObjectDataSource1.Selecting
        e.InputParameters(
"SearchString") = Me.SearchName
        e.InputParameters(
"PrimaryKey") = Me.PrimaryKey
        e.InputParameters(
"Enabled") = Me.IsEnabled
    
End Sub

Data Access Layer

    Public Class My_DAL

        
Public Sub New()
        
End Sub

        Shared Function SelectSP(ByVal PrimaryKey As Int32, ByVal SearchString As String, _
                                         
ByVal IsEnabled As BooleanAs System.Data.DataTable
            
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("connString").ConnectionString)

            
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
            dbCommand.CommandText = 
"usp_MyProc"
            dbCommand.CommandType = CommandType.StoredProcedure
            dbCommand.Connection = dbConnection

            
Dim dbParam_PrimaryKey As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_PrimaryKey .ParameterName = 
"@PrimaryKey"
            dbParam_PrimaryKey .Value = PrimaryKey 
            dbParam_PrimaryKey .DbType = DbType.String
            dbCommand.Parameters.Add(dbParam_PrimaryKey)

            
Dim dbParam_SearchString As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_SearchString.ParameterName = 
"@SearchString"
            dbParam_SearchString.Value = SearchString
            dbParam_SearchString.DbType = DbType.String
            dbCommand.Parameters.Add(dbParam_SearchString)

            
Dim dbParam_IsEnabled As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
            dbParam_IsEnabled.ParameterName = 
"@IsEnabled"
            dbParam_IsEnabled.Value = IsEnabled
            dbParam_IsEnabled.DbType = DbType.String
            dbCommand.Parameters.Add(dbParam_IsEnabled)

            
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
            dataAdapter.SelectCommand = dbCommand
            
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
            dataAdapter.Fill(dataSet)
            
Dim dt As DataTable
            dt = dataSet.Tables(0)
            
Return dt
        
End Function

    End Class
Added on 29 Jun 2008

Solution Summary:
Ensure that the ObjectDatasource InputParameters are spelled correctly and match the names of the parameters specified in the SelectMethod.
Solution Details:
In the scenario above, the error was caused by a simple typo in the code behind.  where the IsEnabled input parameter is set.  The parameter name is not "Enabled", but rather "IsEnabled".
Was this solution useful? Yes No Added on 29 Jun 2008
Rating: 

Copyright 2010 © E-Centric, Inc. | Terms of Use