8 Replies - 429 Views - Last Post: 01 May 2019 - 02:11 PM Rate Topic: -----

#1 darthvader45   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 21-February 13

InvalidOperationException when Updating Database

Posted 30 April 2019 - 07:20 AM

I am trying to make a page where the user can update incident data shown in a gridview. However, I seem to get the following error upon testing the update function:

System.InvalidOperationException: ObjectDataSource 'odsIncidents' could not find a non-generic method 'UpdateIncident' that has parameters: original_Incident, incident, IncidentID, ProductCode, DateOpened, original_IncidentID, original_ProductCode, original_DateOpened.

odsIncidents is bound to the business object IncidentDB.vb which indeed contains the aforementioned method with the indicated parameters in it. If my ObjectDataSource is still missing vital information, what am I missing? Any information regarding this problem is greatly appreciated.

My Files: https://www.dropbox....tError.zip?dl=1

Is This A Good Question/Topic? 0
  • +

Replies To: InvalidOperationException when Updating Database

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6795
  • View blog
  • Posts: 28,082
  • Joined: 12-December 12

Re: InvalidOperationException when Updating Database

Posted 30 April 2019 - 07:24 AM

Please post relevant code directly here in the forum (between code tags), not just as an external resource.
Was This Post Helpful? 1
  • +
  • -

#3 darthvader45   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 21-February 13

Re: InvalidOperationException when Updating Database

Posted 30 April 2019 - 07:27 AM

The source for IncidentUpdate.aspx:

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="IncidentUpdate.aspx.vb" Inherits="Assignment1JL.IncidentUpdate" %>
<asp:Content ID="Content1" ContentPlaceHolderID="headPlaceHolder" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="formPlaceHolder" runat="server">
    <asp:DropDownList ID="ddlCustomer" runat="server" DataSourceID="odsCustomer" DataTextField="Name" DataValueField="CustomerID" AutoPostBack="True">
    </asp:DropDownList>
    <asp:GridView ID="gvCustomerIncidents" runat="server" DataSourceID="odsIncidents" AutoGenerateColumns="False">
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:TemplateField HeaderText="ID" SortExpression="IncidentID">
                <ItemTemplate>
                    <asp:Label ID="lblIncidentID" runat="server" Text='<%# Bind("IncidentID") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Product code" SortExpression="ProductCode">
                <ItemTemplate>
                    <asp:Label ID="lblProductCode" runat="server" Text='<%# Bind("ProductCode") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Date opened" SortExpression="DateOpened">
                <ItemTemplate>
                    <asp:Label ID="lblDateOpened" runat="server" Text='<%# Bind("DateOpened") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Date closed" SortExpression="DateClosed">
                <EditItemTemplate>
                    <asp:TextBox ID="txtDateClosed" runat="server" Text='<%# Eval("DateClosed") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblDateClosed" runat="server" Text='<%# Bind("DateClosed") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Title" SortExpression="Title">
                <ItemTemplate>
                    <asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Description" SortExpression="Description"><EditItemTemplate>
                    <asp:TextBox ID="txtDescription" runat="server" Text='<%# Eval("Description") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblDescription" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                </ItemTemplate></asp:TemplateField>
        </Columns>
        <EditRowStyle HorizontalAlign="Right" />
    </asp:GridView>
    <asp:ObjectDataSource ID="odsCustomer" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCustomersWithIncidents" TypeName="CustomerDB"></asp:ObjectDataSource>
    <asp:ObjectDataSource ID="odsIncidents" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCustomerIncidents" TypeName="Assignment1JL.IncidentDB" UpdateMethod="UpdateIncident" ConflictDetection="CompareAllValues">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlCustomer" Name="CustomerID" PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="original_Incident" Type="Object" />
            <asp:Parameter Name="incident" Type="Object" />
            <asp:Parameter Name="IncidentID" Type="Int32" />
            <asp:Parameter Name="ProductCode" Type="String" />
            <asp:Parameter Name="DateOpened" Type="DateTime" />
            <asp:Parameter Name="original_IncidentID" Type="Int32" />
            <asp:Parameter Name="original_ProductCode" Type="String" />
            <asp:Parameter Name="original_DateOpened" Type="DateTime" />
        </UpdateParameters>
    </asp:ObjectDataSource>
&nbsp;
</asp:Content>

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6795
  • View blog
  • Posts: 28,082
  • Joined: 12-December 12

Re: InvalidOperationException when Updating Database

Posted 01 May 2019 - 01:24 AM

Quote

System.InvalidOperationException: ObjectDataSource 'odsIncidents' could not find a non-generic method 'UpdateIncident' that has parameters: original_Incident, incident, IncidentID, ProductCode, DateOpened, original_IncidentID, original_ProductCode, original_DateOpened.

odsIncidents is bound to the business object IncidentDB.vb which indeed contains the aforementioned method with the indicated parameters in it.

The error says it cannot find it so post the code for the method (and any other relevant details). There might be

a missing or additional parameter...
the method may be inaccessible...
it is in the wrong namespace or location.
Was This Post Helpful? 0
  • +
  • -

#5 darthvader45   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 21-February 13

Re: InvalidOperationException when Updating Database

Posted 01 May 2019 - 04:21 AM

Code for IncidentDB.vb, including the mentioned UpdateIncident method.

Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.ComponentModel
Imports System.Data

<DataObject(True)>
Public Class IncidentDB

    <DataObjectMethod(DataObjectMethodType.Select)>
    Public Function GetOpenTechIncidents(ByVal techID As Integer) As IEnumerable
        Dim con As New SqlConnection(TechSupportDB.GetConnectionString)
        Dim sel As String = "SELECT DateOpened, ProductCode, Name " &
            "FROM Incidents INNER JOIN Customers " &
            "ON Incidents.CustomerID = Customers.CustomerID " &
            "WHERE DateClosed IS NULL " &
            "AND TechID = @TechID " &
            "ORDER BY DateOpened"
        Dim cmd As New SqlCommand(sel, con)
        cmd.Parameters.AddWithValue("TechID", techID)
        con.Open()
        Dim rdr As SqlDataReader =
            cmd.ExecuteReader(Commandbehavior.CloseConnection)
        Return rdr

    End Function

    <DataObjectMethod(DataObjectMethodType.Select)>
    Public Shared Function GetCustomerIncidents(ByVal CustomerID As Integer) _
            As IEnumerable
        Dim con As New SqlConnection(TechSupportDB.GetConnectionString)
        Dim sel As String = "SELECT IncidentID, ProductCode, " &
                            "DateOpened, DateClosed, Title, Description " &
                            "FROM Incidents " &
                            "WHERE CustomerID = @CustomerID " &
                            "AND TechID IS NOT NULL"
        Dim cmd As New SqlCommand(sel, con)
        cmd.Parameters.AddWithValue("CustomerID", CustomerID)
        con.Open()
        Dim rdr As SqlDataReader = cmd.ExecuteReader(Commandbehavior.CloseConnection)
        Return rdr
    End Function

    <DataObjectMethod(DataObjectMethodType.Update)>
    Public Shared Function UpdateIncident(
            ByVal original_Incident As Incident,
            ByVal incident As Incident) As Integer
        Dim con As New SqlConnection(TechSupportDB.GetConnectionString)
        Dim up As String = "UPDATE Incidents " &
                           "SET DateClosed = @DateClosed, " &
                           "Description = @Description " &
                           "WHERE IncidentID = @original_IncidentID " &
                           "AND ProductCode = @original_ProductCode " &
                           "AND DateOpened = @original_DateOpened " &
                           "AND (DateClosed = @original_DateClosed " &
                           "OR DateClosed IS NULL " &
                           "AND @original_DateClosed IS NULL) " &
                           "AND Title = @original_Title " &
                           "AND Description = @original_Description"
        Dim cmd As New SqlCommand(up, con)
        If incident.DateClosed = #12:00:00 AM# Then
            cmd.Parameters.AddWithValue("DateClosed", DBNull.Value)
        Else
            cmd.Parameters.AddWithValue("DateClosed", incident.DateClosed)
        End If
        cmd.Parameters.AddWithValue("Description", incident.Description)
        cmd.Parameters.AddWithValue("original_IncidentID", original_Incident.IncidentID)
        cmd.Parameters.AddWithValue("original_ProductCode", original_Incident.ProductCode)
        cmd.Parameters.AddWithValue("original_DateOpened", original_Incident.DateOpened)
        If original_Incident.DateClosed = #12:00:00 AM# Then
            cmd.Parameters.AddWithValue("original_DateClosed", DBNull.Value)
        Else
            cmd.Parameters.AddWithValue("original_DateClosed", original_Incident.DateClosed)
        End If
        cmd.Parameters.AddWithValue("original_Title", original_Incident.Title)
        cmd.Parameters.AddWithValue("original_Description", original_Incident.Description)
        con.Open()
        Dim i As Integer = cmd.ExecuteNonQuery()
        con.Close()
        Return i
    End Function

End Class


Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6795
  • View blog
  • Posts: 28,082
  • Joined: 12-December 12

Re: InvalidOperationException when Updating Database

Posted 01 May 2019 - 05:22 AM

That method has two parameters, not eight.
Was This Post Helpful? 0
  • +
  • -

#7 darthvader45   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 21-February 13

Re: InvalidOperationException when Updating Database

Posted 01 May 2019 - 01:54 PM

Okay, now the error I'm getting is a NullReferenceException. The error references Line 60 of IncidentDB.vb, so I assume something needs to change there.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15061
  • View blog
  • Posts: 60,147
  • Joined: 12-June 08

Re: InvalidOperationException when Updating Database

Posted 01 May 2019 - 02:07 PM

Why are the functions 'shared'?

Is this a ASP.NET webform?

Put a breakpoint on 'UpdateIncident' and see what the variables are coming in.
Was This Post Helpful? 0
  • +
  • -

#9 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 223
  • View blog
  • Posts: 1,260
  • Joined: 05-December 13

Re: InvalidOperationException when Updating Database

Posted 01 May 2019 - 02:11 PM

instantiate a reference, in this case, (at a glance) I don't see anywhere you do that in this code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1