locked
DataSet Tableadapter & ObjectDataSource RRS feed

  • Question

  • User-120165138 posted

    Hi,

    Im am just getting started with .net and have begun building a system from a tutorial that I found online (http://msdn.microsoft.com/en-us/library/bb288041.aspx) but Im having problems with my inserts, updates, and deletes. I have found a bunch of forum posts that refer to the same problem, but most are old and the solutions really dont make alot of sence to me. After creating both the DAL & BLL I use an objectdatasource to connect to a listview, but whenever I update/insert/delete I get this error (below). Can anyone help me out with a good solution. In general Im just trying to create a ntier website, im just starting out with c# and am pretty good with sql are there any better (easy) options?

    Thanks

    ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 

     

     

     

    Friday, February 25, 2011 10:34 PM

Answers

  • User-120165138 posted

    I figured it out, kinda. The answer is to quit using datasets and move to linq or entity frame work.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 14, 2011 2:32 PM

All replies

  • User-693248168 posted

    Can you show us the code you are using for updating/inserting/deleting from the objectdataSource?

    Saturday, February 26, 2011 4:02 AM
  • User-120165138 posted

    Here are the sets Ive takes up to the error:

    #1 I created a dataset (for my DAL) and added a tableadapter the has the basic Get/Fill options w/ the autogenerate insert/update/delete. I also added a custom insert (and plan to add custom update later too) because banner_id & milleniumid are both foreign keys that link some people to other db's. Refresh the data table & Use optimistic concurrency were not selected.

    #2 I create a class "bllPeople.cs" for my business logic layer. For the most part Im not adding any buisness logic yet, just using it as a proxy to access the DAL. Code below.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using DALTableAdapters;
    using System.ComponentModel;
    /// <summary>
    /// Summary description for bllPeople
    /// </summary>
    public class bllPeople
    {
        private PeopleBasicTableAdapter _peopleAdapter = null;
        protected PeopleBasicTableAdapter Adapter
        {
            get
            {
                if (_peopleAdapter == null)
                    _peopleAdapter = new PeopleBasicTableAdapter();
    
                return _peopleAdapter;
            }
        }
    
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public DAL.PeopleBasicDataTable GetPeopleBasic()
        {
            return Adapter.GetPeopleBasic();
        }
    
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public DAL.PeopleBasicDataTable GetPeopleBasicByBannerId(string banner_id)
        {
            return Adapter.GetPeopleBasicByBannerId(banner_id);
        }
    
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public bool PeopleBasicInsert(string first_name, string middle_name, string last_name, DateTime birthdate,
            string gender_code, string title, string restrictedcontact, string handicapstatus, DateTime moddate)
        {
            DAL.PeopleBasicDataTable people = new DAL.PeopleBasicDataTable();
            DAL.PeopleBasicRow person = people.NewPeopleBasicRow();
    
            person.FIRST_NAME = first_name;
            if (middle_name == null) person.SetMIDDLE_NAMENull();
            else person.MIDDLE_NAME = middle_name;
            person.LAST_NAME = last_name;
            if (birthdate == null) person.SetBIRTHDATENull();
            else person.BIRTHDATE = birthdate;
            if (gender_code == null) person.SetGENDER_CODENull();
            else person.GENDER_CODE = gender_code;
            if (title == null) person.SetTitleNull();
            else person.Title = title;
            if (restrictedcontact == null) person.SetRestrictedContactNull();
            else person.RestrictedContact = restrictedcontact;
            if (handicapstatus == null) person.SetHandicapStatusNull();
            else person.HandicapStatus = handicapstatus;
            person.ModDate = DateTime.Now;
    
            //Add the new person
            people.AddPeopleBasicRow(person);
            int rowAffected = Adapter.Update(people);
    
            // Return true if precisely one row was deleted,
            // otherwise false
            return rowAffected == 1;
        }
    
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public bool PeopleBasicUpdate(string first_name, string middle_name, string last_name, DateTime birthdate,
            string gender_code, string title, string restrictedcontact, string handicapstatus, DateTime moddate,
            string banner_id)
        {
            DAL.PeopleBasicDataTable people = Adapter.GetPeopleBasicByBannerId(banner_id);
            if (people.Count == 0)
                //no matching record found, return false
                return false;
    
            DAL.PeopleBasicRow person = people[0];
    
            person.FIRST_NAME = first_name;
            if (middle_name == null) person.SetMIDDLE_NAMENull();
            else person.MIDDLE_NAME = middle_name;
            person.LAST_NAME = last_name;
            if (birthdate == null) person.SetBIRTHDATENull();
            else person.BIRTHDATE = birthdate;
            if (gender_code == null) person.SetGENDER_CODENull();
            else person.GENDER_CODE = gender_code;
            if (title == null) person.SetTitleNull();
            else person.Title = title;
            if (restrictedcontact == null) person.SetRestrictedContactNull();
            else person.RestrictedContact = restrictedcontact;
            if (handicapstatus == null) person.SetHandicapStatusNull();
            else person.HandicapStatus = handicapstatus;
            person.CreateDate = DateTime.Now;
            person.ModDate = DateTime.Now;
    
            // Update the person record
            int rowAffected = Adapter.Update(person);
    
            // Return true if precisely one row was updated, otherwise false
            return rowAffected == 1;
        }
    
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public bool PeopleBasicDelete(int hnumber)
        {
            int rowAffected = Adapter.Delete(hnumber);
    
            // Return true if precisely one row was deleted,
            // otherwise false
            return rowAffected == 1;
        }
    
        public bllPeople()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }

     

    #3 I add at aspx page including a gridview & objectdatasource connecting to the bllPeople for insert/update/delete and enabled editing & deleting.

    <%@ Page Title="" Language="C#" MasterPageFile="~/Root.master" AutoEventWireup="true"
        CodeFile="Test.aspx.cs" Inherits="Test" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" DataKeyNames="HNUMBER" 
            DataSourceID="ObjectDataSource1">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="CONFIDENTIALITY" HeaderText="CONFIDENTIALITY" 
                    SortExpression="CONFIDENTIALITY" />
                <asp:BoundField DataField="HNUMBER" HeaderText="HNUMBER" InsertVisible="False" 
                    ReadOnly="True" SortExpression="HNUMBER" />
                <asp:BoundField DataField="MILLENNIUM_ID" HeaderText="MILLENNIUM_ID" 
                    SortExpression="MILLENNIUM_ID" />
                <asp:BoundField DataField="BANNER_ID" HeaderText="BANNER_ID" 
                    SortExpression="BANNER_ID" />
                <asp:BoundField DataField="FIRST_NAME" HeaderText="FIRST_NAME" 
                    SortExpression="FIRST_NAME" />
                <asp:BoundField DataField="MIDDLE_NAME" HeaderText="MIDDLE_NAME" 
                    SortExpression="MIDDLE_NAME" />
                <asp:BoundField DataField="LAST_NAME" HeaderText="LAST_NAME" 
                    SortExpression="LAST_NAME" />
                <asp:BoundField DataField="NAME_PREFIX" HeaderText="NAME_PREFIX" 
                    SortExpression="NAME_PREFIX" />
                <asp:BoundField DataField="BIRTHDATE" HeaderText="BIRTHDATE" 
                    SortExpression="BIRTHDATE" />
                <asp:BoundField DataField="GENDER_CODE" HeaderText="GENDER_CODE" 
                    SortExpression="GENDER_CODE" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="RestrictedContact" HeaderText="RestrictedContact" 
                    SortExpression="RestrictedContact" />
                <asp:BoundField DataField="HandicapStatus" HeaderText="HandicapStatus" 
                    SortExpression="HandicapStatus" />
                <asp:BoundField DataField="CreateDate" HeaderText="CreateDate" 
                    SortExpression="CreateDate" />
                <asp:BoundField DataField="ModDate" HeaderText="ModDate" 
                    SortExpression="ModDate" />
            </Columns>
        </asp:GridView>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            DeleteMethod="PeopleBasicDelete" InsertMethod="PeopleBasicInsert" 
            SelectMethod="GetPeopleBasic" TypeName="bllPeople" 
            UpdateMethod="PeopleBasicUpdate">
            <DeleteParameters>
                <asp:Parameter Name="hnumber" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="first_name" Type="String" />
                <asp:Parameter Name="middle_name" Type="String" />
                <asp:Parameter Name="last_name" Type="String" />
                <asp:Parameter Name="birthdate" Type="DateTime" />
                <asp:Parameter Name="gender_code" Type="String" />
                <asp:Parameter Name="title" Type="String" />
                <asp:Parameter Name="restrictedcontact" Type="String" />
                <asp:Parameter Name="handicapstatus" Type="String" />
                <asp:Parameter Name="moddate" Type="DateTime" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="first_name" Type="String" />
                <asp:Parameter Name="middle_name" Type="String" />
                <asp:Parameter Name="last_name" Type="String" />
                <asp:Parameter Name="birthdate" Type="DateTime" />
                <asp:Parameter Name="gender_code" Type="String" />
                <asp:Parameter Name="title" Type="String" />
                <asp:Parameter Name="restrictedcontact" Type="String" />
                <asp:Parameter Name="handicapstatus" Type="String" />
                <asp:Parameter Name="moddate" Type="DateTime" />
                <asp:Parameter Name="banner_id" Type="String" />
            </UpdateParameters>
        </asp:ObjectDataSource>
    </asp:Content>
    

     

    #4 The gridview displays the data, but if I click edit and update I get this error (below). I am able to connect directly to the DAL and insert/update/delete, but seem to get this error no matter what I try with the BLL.  I have read alot of older forum posts (2005) that talk about switching original_{0} to {0} in the objectdatasource, but mine does not include this, and others that talk about the problem being Refresh the data table and/or Use optimistic concurrency being selected which require original_{0}, but I did not select any of these.

    Any help would be Great.

    Server Error in '/' Application.
    
    ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'PeopleBasicUpdate' that has parameters: FIRST_NAME, MIDDLE_NAME, LAST_NAME, BIRTHDATE, GENDER_CODE, Title, RestrictedContact, HandicapStatus, ModDate, BANNER_ID, CONFIDENTIALITY, MILLENNIUM_ID, NAME_PREFIX, CreateDate, HNUMBER.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: System.InvalidOperationException: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'PeopleBasicUpdate' that has parameters: FIRST_NAME, MIDDLE_NAME, LAST_NAME, BIRTHDATE, GENDER_CODE, Title, RestrictedContact, HandicapStatus, ModDate, BANNER_ID, CONFIDENTIALITY, MILLENNIUM_ID, NAME_PREFIX, CreateDate, HNUMBER.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    
    Stack Trace: 
    
    
    [InvalidOperationException: ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'PeopleBasicUpdate' that has parameters: FIRST_NAME, MIDDLE_NAME, LAST_NAME, BIRTHDATE, GENDER_CODE, Title, RestrictedContact, HandicapStatus, ModDate, BANNER_ID, CONFIDENTIALITY, MILLENNIUM_ID, NAME_PREFIX, CreateDate, HNUMBER.]
       System.Web.UI.WebControls.ObjectDataSourceView.GetResolvedMethodData(Type type, String methodName, IDictionary allParameters, DataSourceOperation operation) +2627172
       System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +1778
       System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +3635717
       System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +1336
       System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +641
       System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +164
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +52
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

     

     

    Saturday, February 26, 2011 2:50 PM
  • User-120165138 posted

    I figured it out, kinda. The answer is to quit using datasets and move to linq or entity frame work.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 14, 2011 2:32 PM