InvalidOperationException: ObjectDataSource could not find a non-generic method that has parameters:

18,878

Solution 1

From the ObjectDataSource, I would say yes you're using TypeName wrong. In the MSDN article, it refers to the class which hosts the method, not the return type of the method.

Try changing TypeName="System.Data.DataTable" to TypeName="AcpServiceNS.Reporter"

Solution 2

Your typename must show your service type like below;

                <asp:ObjectDataSource ID="odsPoint" runat="server" SortParameterName="sortColumns" EnablePaging="True" 
                    StartRowIndexParameterName="startRecord" MaximumRowsParameterName="maxRecords"
                    SelectCountMethod="GetCategoryPoints" SelectMethod="GetCategoryPointsByFilters" 
                    TypeName="EvaluationAssistt.Service.Services.EvaluationReportingService" 
                    UpdateMethod="GetCategoryPointsByFilters">

Care about here: TypeName="EvaluationAssistt.Service.Services.EvaluationReportingService" where is your service method write here the path (such as strong name;-)

Share:
18,878
jp2code
Author by

jp2code

Software Developer @ IPKeys and jp2code.net Long ago, I left home and joined the United States Marine Corps where I was assigned the Military Occupational Specialty (MOS) of Basic Metal Worker (MOS 1316). I loved building things as a welder, but could not see myself doing this until I reached age 65. After my Honorable Discharge in the early 1990s, I used my G.I. Bill to go to school and received my Bachelor of Science Degree in Physics four years later. Using a love of computers since I played on a Commodore 64 at 10 years old and two (2) C++ electives that I had taken in school, I began working in the computer programming field. The recession following ENRON in 2001 left me working at a remedial job for a little over two years while I brushed up on my skills at a local community college in SQL and first learned what the new .NET Framework was all about. I have had the pleasure of working as a Software Developer since 2003. For a short while, I pulled in a little extra income by running a moonlighting business under the name Joe's Welding. Dangerous working conditions and non-paying customers prompted me to sell my mobile welding equipment about the time my son was born. Today, I am exclusively a Software Developer. My language of choice is C#, and I enjoy working with databases. If you care to find me anywhere else, just do a search on my screen name: jp2code

Updated on July 24, 2022

Comments

  • jp2code
    jp2code almost 2 years

    I'm trying to code an ObjectDataSource for a local ASP.NET page.

    Reading the Help files on MSDN always leave me scratching my head, wondering what exactly they might be implying. For example, I am not sure what my TypeName should be (though that link has an interesting example).

    Once I get the basics to work, I will venture into deeper waters.

    The first line of my *.aspx file contains my definitions:

    <%@ Page Title="Reporter" Language="C#" MasterPageFile="~/local.Master"
        AutoEventWireup="true" CodeBehind="Reporter.aspx.cs"
        Inherits="AcpServiceNS.Reporter" %>
    

    In this page, I have TextBox controls named txtStartDate and txtEndDate and a number of DropDownList controls named ddlStartTime, ddlEndTime, ddlAction, ddlFilter1, and ddlFilter2.

    I also have the following ObjectDataSource:

    <asp:ObjectDataSource ID="dsReport" runat="server"
         SelectMethod="GetData"
         TypeName="System.Data.DataTable"
         ConvertNullToDBNull="True" >
      <SelectParameters>
        <asp:ControlParameter ControlID="txtStartDate" Name="startDate" PropertyName="Text" Type="String" DefaultValue="" />
        <asp:ControlParameter ControlID="ddlStartTime" Name="startTime" PropertyName="Text" Type="String" DefaultValue="" />
        <asp:ControlParameter ControlID="txtEndDate" Name="endDate" PropertyName="Text" Type="String" DefaultValue="" />
        <asp:ControlParameter ControlID="ddlEndTime" Name="endTime" PropertyName="Text" Type="String" DefaultValue="" />
        <asp:ControlParameter ControlID="ddlAction" Name="action1" PropertyName="Text" Type="String" DefaultValue="" />
        <asp:ControlParameter ControlID="ddlFilter1" Name="filter1" PropertyName="Text" Type="String" DefaultValue="" />
        <asp:ControlParameter ControlID="ddlFilter2" Name="filter2" PropertyName="Text" Type="String" DefaultValue="" />
      </SelectParameters>
    </asp:ObjectDataSource>
    

    A GridView control is going to be on the *.aspx page, and will be used to display the data:

    <asp:GridView ID="gvReport" AllowSorting="true" AutoGenerateColumns="false" AllowPaging="true" Font-Size="Small" PageSize="30" Width="100%"
      OnRowDataBound="Report_RowDataBound"
      OnRowCommand="Report_RowCommand"
      DataKeyNames="Op_ID,Serial_Number,Date_Time,Test_Result"
      DataSourceID="dsReport"
      runat="server">
      <Columns>
        <asp:TemplateField HeaderText="Op_ID" HeaderStyle-Width="20%">
          <ItemTemplate>
            <asp:LinkButton ID="lbOp_ID" runat="server" CommandArgument='<%# Container.DataItemIndex %>' CommandName="Op_ID" />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Serial_Number" HeaderStyle-Width="20%">
          <ItemTemplate>
            <asp:LinkButton ID="lbSerial_Number" runat="server" CommandArgument='<%# Container.DataItemIndex %>' CommandName="Serial_Number" />
          </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="Date_Time" HeaderText="Date_Time" SortExpression="Date_Time" HeaderStyle-Width="20%" />
        <asp:BoundField DataField="Test_Result" HeaderText="Test_Result" SortExpression="Test_Result" HeaderStyle-Width="40%" />
      </Columns>
    </asp:GridView>
    

    To get this to load an empty dataset, I have created this simple stub in my codebehind:

    namespace AcpServiceNS {
    
      public partial class Reporter : System.Web.UI.Page {
    
        protected void Page_Load(object sender, EventArgs e) {
        }
    
        [DataObjectMethod(DataObjectMethodType.Select)]
        protected static DataTable GetData(string startDate, string startTime, string endDate, string endTime,
          string action1, string filter1, string filter2) {
          var table = new DataTable();
          table.Columns.Add("Op_ID", typeof(string));
          table.Columns.Add("Serial_Number", typeof(string));
          table.Columns.Add("Date_Time", typeof(DateTime));
          table.Columns.Add("Test_Result", typeof(string));
          return table;
        }
    
      }
    
    }
    

    Yes! All that is above is basically a Table Definition, but it should be enough to start my *.aspx page.

    When I try to run this, I get the following Exception:

    System.InvalidOperationException: ObjectDataSource 'dsReport' could not find a non-generic method 'GetData' that has parameters: startDate, startTime, endDate, endTime, action1, filter1, filter2.

    It appears that I have spelled and cased all of the parameters correctly, so what have I done wrong? Is TypeName used incorrectly?