locked
Insert Not Working - Adding Additional Parameters to Insert From DetailsView RRS feed

  • Question

  • User-1913002659 posted

    Getting the message that ObjectDataSource ... count not find a non-generic method ... that has parameters ...  The parameter list is fine until I get to the very end and it list the two data fields that are in my DetailsView.  Using the ASP Tutorial #17 (Examining the Events Associated with Inserting, Updating, and Deleting) and the Exploring the Data Modification - specifically the one showing the INSERT of the Product Name and UnitPrice.  ASPX page is pretty simple and attempting something similar, two fields to insert a new record - update the other fields later.

    Full Error Message follows along with ASPX and the AsignaturasBLL.cs.  Interesting thing is that when I swap the two fields in the DetailView, then the last two fields in the error message are swapped.  In the error message I bolded these two fields.

    Error in: http://localhost:57548/SimpleUpdate/CourseBuilder.aspx
    Error Message: ObjectDataSource 'AsignaturasDataSource' could not find a non-generic method 'AddAsignatura' that has parameters: Nombre, CodigoPlanBasico, Area, Unidades, Nivel, Curso, Descripcion, Especialidad, Numeracion, Fecha, Prerrequisito, RevisionPersona, RevisionFecha, NoEnCatalogo, AsignaturaCodigoPlanBasico, AsignaturaNombre.
    Stack Trace:
    at System.Web.UI.WebControls.ObjectDataSourceView.GetResolvedMethodData(Type type, String methodName, IDictionary allParameters, DataSourceOperation operation) at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteInsert(IDictionary values) at System.Web.UI.DataSourceView.Insert(IDictionary values, DataSourceViewOperationCallback callback) at System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg, Boolean causesValidation) at System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) at System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Here is the ASPX page
    <%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="CourseBuilder.aspx.cs"
        Inherits="CourseBuilder" Title="Constructor de Cursos" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
        <h3>
            Constructor de Cursos</h3>
        <p>
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="ClaveAsignaturas" 
                DataSourceID="AsignaturasDataSource" DefaultMode="Insert">
                <Fields>
                    <asp:BoundField DataField="AsignaturaCodigoPlanBasico" 
                        HeaderText="AsignaturaCodigoPlanBasico" 
                        SortExpression="AsignaturaCodigoPlanBasico" />
                    <asp:BoundField DataField="AsignaturaNombre" HeaderText="AsignaturaNombre" 
                        SortExpression="AsignaturaNombre" />
                    <asp:CommandField ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView>
        </p>
        <p>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ClaveAsignaturas" 
                DataSourceID="AsignaturasDataSource" >
                <Columns>
                    <asp:CommandField ShowEditButton="True" />
                    <asp:BoundField DataField="AsignaturaNombre" HeaderText="AsignaturaNombre" 
                        SortExpression="AsignaturaNombre" />
                    <asp:BoundField DataField="AsignaturaCodigoPlanBasico" 
                        HeaderText="AsignaturaCodigoPlanBasico" 
                        SortExpression="AsignaturaCodigoPlanBasico" />
                </Columns>
            </asp:GridView>
            <asp:ObjectDataSource ID="AsignaturasDataSource" runat="server" SelectMethod="GetAsignaturas" 
                TypeName="AsignaturasBLL" UpdateMethod="UpdateAsignatura" InsertMethod="AddAsignatura" 
                OldValuesParameterFormatString="{0}">
                <UpdateParameters>
                    <asp:Parameter Name="Nombre" Type="String" />
                    <asp:Parameter Name="CodigoPlanBasico" Type="String" />
                    <asp:Parameter Name="claveAsignaturas" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="Nombre" Type="String" />
                    <asp:Parameter Name="CodigoPlanBasico" Type="String" />
                    <asp:Parameter Name="Area" Type="String" />
                    <asp:Parameter Name="Unidades" Type="Int16" />
                    <asp:Parameter Name="Nivel" Type="String" />
                    <asp:Parameter Name="Curso" Type="String" />
                    <asp:Parameter Name="Descripcion" Type="String" />
                    <asp:Parameter Name="Especialidad" Type="String" />
                    <asp:Parameter Name="Numeracion" Type="String" />
                    <asp:Parameter Name="Fecha" Type="DateTime" />
                    <asp:Parameter Name="Prerrequisito" Type="Int32" />
                    <asp:Parameter Name="RevisionPersona" Type="String" />
                    <asp:Parameter Name="RevisionFecha" Type="DateTime" />
                    <asp:Parameter Name="NoEnCatalogo" Type="Boolean" />
                </InsertParameters>
            </asp:ObjectDataSource>
        </p>
    </asp:Content>
    
    Here is the AddAsignatura that is part of the AsignaturaBLL.cs
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public bool AddAsignatura(string Nombre, string CodigoPlanBasico, string Area, 
            short? Unidades, string Nivel, string Curso, string Descripcion, 
            string Especialidad, string Numeracion, DateTime Fecha,
            int Prerrequisito, string RevisionPersona, DateTime RevisionFecha, bool NoEnCatalogo)
        {
            // Create a new AsignaturaRow instance
            PlanBasico.AsignaturasDataTable asignaturas = new PlanBasico.AsignaturasDataTable();
            PlanBasico.AsignaturasRow asignatura = asignaturas.NewAsignaturasRow();
    
            asignatura.AsignaturaNombre = Nombre;
            asignatura.AsignaturaCodigoPlanBasico = CodigoPlanBasico;
            //if (Nombre == null) asignatura.SetAsignaturaNombreNull(); else asignatura.AsignaturaNombre = Nombre;
            //if (CodigoPlanBasico == null) asignatura.SetAsignaturaCodigoPlanBasicoNull(); else asignatura.AsignaturaCodigoPlanBasico = CodigoPlanBasico;
    
            if (Area == null) asignatura.SetAsignaturaAreaNull(); else asignatura.AsignaturaArea = Area;
            if (Unidades == null) asignatura.SetAsignaturaUnidadesNull(); else asignatura.AsignaturaUnidades = Unidades.Value;
            if (Nivel == null) asignatura.SetAsignaturaNivelNull(); else asignatura.AsignaturaNivel = Nivel;
            if (Curso == null) asignatura.SetAsignaturaCursoNull(); else asignatura.AsignaturaCurso = Curso;
            if (Descripcion == null) asignatura.SetAsignaturaDescripcionNull(); else asignatura.AsignaturaDescripcion = Descripcion;
            if (Especialidad == null) asignatura.SetAsignaturaEspecialidadNull(); else asignatura.AsignaturaEspecialidad = Especialidad;
            if (Numeracion == null) asignatura.SetAsignaturaNumeracionNull(); else asignatura.AsignaturaNumeracion = Numeracion;
            if (Fecha == null) asignatura.SetAsignaturaFechaNull(); else asignatura.AsignaturaFecha = Fecha;
            if (Prerrequisito == null) asignatura.SetAsignaturaPrerrequisitoNull(); else asignatura.AsignaturaPrerrequisito = Prerrequisito;
            if (RevisionPersona == null) asignatura.SetAsignaturaRevisionPersonaNull(); else asignatura.AsignaturaRevisionPersona = RevisionPersona;
    
            if (RevisionFecha == null) asignatura.SetAsignaturaRevisionFechaNull(); else asignatura.AsignaturaRevisionFecha = RevisionFecha;
            asignatura.AsignaturaNoEnCatalogo = NoEnCatalogo;
    
            // Add the new asignatura
            
            asignaturas.AddAsignaturasRow(asignatura);
            int rowsAffected = Adapter.Update(asignaturas);
    
            // Return true if precisely one row was inserted, otherwise false
            return rowsAffected == 1;
        }
    


     

    Tuesday, July 13, 2010 4:05 PM

Answers

  • User-1913002659 posted

    This might be just ignorance on my part and just too new at using C# & Web development, but I thought everything was set just like the tutorial.  The error message shows the 14 data fields in my Access DB, but added the two fields to the end.  As you pointed out, these are the two bound fields within my DetailsView.  These two fields are the same as Nombre & CodigoPlanBasico in my DB.

    Well - you got me thinking about this - turns out it was just a naming issue.  The two fields that I have Bound, then need to be the references used in the Insert Parameters.  When I used the Bound names I could eliminate the additional two fields.

    Thanks for helping this old dog learn new tricks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 15, 2010 9:32 AM

All replies

  • User-2091578272 posted

    Error shows that the method "AddAsignatura" in your ObjectDataSource don't handle the extra parameters  "AsignaturaCodigoPlanBasico, AsignaturaNombre"


    Wednesday, July 14, 2010 1:16 AM
  • User-1913002659 posted

    I understand that, what I don't understand is why the extra parameters were put there - what generated them.

    I attempted to provide all the code associated with the simple ASPX page.  So where do these come from? 

    Wednesday, July 14, 2010 9:38 AM
  • User-1199946673 posted

    So where do these come from?
     

    Because you bound those fields in the detailsview. Try setting the InsertVisible column of the databound fields to false:

    <asp:BoundField DataField="AsignaturaCodigoPlanBasico" InsertVisible="false"    
        HeaderText="AsignaturaCodigoPlanBasico"    
        SortExpression="AsignaturaCodigoPlanBasico" />   
    <asp:BoundField DataField="AsignaturaNombre"  InsertVisible="false"
        HeaderText="AsignaturaNombre" SortExpression="AsignaturaNombre" /> 


     

    Wednesday, July 14, 2010 12:13 PM
  • User-1913002659 posted

    The purpose of the DetailsView is to have the ability to enter those two fields into the Access database.  If I did the InsertVisable to False, then they are not available to enter the value to add.

    Wednesday, July 14, 2010 12:55 PM
  • User-1199946673 posted

    The purpose of the DetailsView is to have the ability to enter those two fields into the Access database.  If I did the InsertVisable to False, then they are not available to enter the value to add.

     

    ??? If you want those fields to be added in the database, how come they are not part of the object datasource  AddAsignatura method?

     

    Wednesday, July 14, 2010 2:04 PM
  • User-1913002659 posted

    This might be just ignorance on my part and just too new at using C# & Web development, but I thought everything was set just like the tutorial.  The error message shows the 14 data fields in my Access DB, but added the two fields to the end.  As you pointed out, these are the two bound fields within my DetailsView.  These two fields are the same as Nombre & CodigoPlanBasico in my DB.

    Well - you got me thinking about this - turns out it was just a naming issue.  The two fields that I have Bound, then need to be the references used in the Insert Parameters.  When I used the Bound names I could eliminate the additional two fields.

    Thanks for helping this old dog learn new tricks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 15, 2010 9:32 AM