title: Using an ObjectDataSource to Update a GridView in ASP.NET
body: <p>I currently am working on a project that is using ObjectDataSources along with a GridView control to run some database access and updating.</p>
  
  <p>The current issue I am running into is that when clicking the Update button within the gridview an exception error is thrown out. From what I understand this error seems to be saying that the grid-view is passing to many parameters to the update statement.</p>
  
  <p>I would like it to send 2 objects, "orignal_Incident" and "incident", which should hold all the fields that I need. But it seems it is also passing along the fields "DateClosed" and "Description".</p>
  
  <p>Is there possibly a way to edit which parameters the gridview sends? Or is there something else that needs to be done to make this work?</p>
  
  <p>Below is the code and errors pertaining to this portion of the program:</p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>ObjectDataSource 'obsIncidents' could not find a non-generic method 'UpdateIncident' that has parameters: original_Incident, incident, DateClosed, Description.</p>
  </blockquote>
  
  <p>ASP.NET code for ObjectDataSource</p>
  
  <pre><code>&lt;asp:ObjectDataSource ID="obsIncidents" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCustomerIncidents" TypeName="IncidentDB" UpdateMethod="UpdateIncident"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:ControlParameter ControlID="ddlCustomer" Name="CustomerID" PropertyName="SelectedValue" Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
      &lt;UpdateParameters&gt;
          &lt;asp:Parameter Name="original_Incident" Type="Object" /&gt;
          &lt;asp:Parameter Name="incident" Type="Object" /&gt;
      &lt;/UpdateParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>ASP.NET code for GridView</p>
  
  <pre><code>&lt;asp:GridView ID="gvIncidents" runat="server" AutoGenerateColumns="False" DataSourceID="obsIncidents" CellPadding="4" ForeColor="#333333" GridLines="None"&gt;
      &lt;AlternatingRowStyle BackColor="White" /&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="IncidentID" HeaderText="ID" ReadOnly="True" ControlStyle-Width="30" /&gt;
          &lt;asp:BoundField DataField="ProductCode" HeaderText="Product Code" ReadOnly="True" ControlStyle-Width="70" /&gt;
          &lt;asp:BoundField DataField="DateOpened" DataFormatString="{0:d}" HeaderText="Date Opened" ReadOnly="True" ControlStyle-Width="70" /&gt;
          &lt;asp:BoundField DataField="DateClosed" HeaderText="Date Closed" DataFormatString="{0:d}" ControlStyle-Width="70" ApplyFormatInEditMode="True" /&gt;
          &lt;asp:BoundField DataField="Title" HeaderText="Title" ReadOnly="True" ControlStyle-Width="150" /&gt;
  
          &lt;asp:TemplateField HeaderText="Description" ControlStyle-Width="300" &gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="lblDescription" runat="server" Text='&lt;%# Eval("Description") %&gt;' Width="300"&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
          &lt;EditItemTemplate&gt;
              &lt;asp:TextBox ID="txtDescription" runat="server" Text='&lt;%# Bind("Description") %&gt;' Width="300" Rows="4" TextMode="MultiLine"&gt;&lt;/asp:TextBox&gt;
          &lt;/EditItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
  
          &lt;asp:CommandField ButtonType="Button" ShowEditButton="True" /&gt;
      &lt;/Columns&gt;
      &lt;EditRowStyle BackColor="#2461BF" /&gt;
      &lt;FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
      &lt;HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt;
      &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt;
      &lt;RowStyle BackColor="#EFF3FB" /&gt;
      &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Visual Basic update method in class-file</p>
  
  <pre><code>&lt;DataObjectMethod(DataObjectMethodType.Update)&gt;
  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 " &amp;
                         "SET DateClosed = @DateClosed, " &amp;
                         "Description = @Description " &amp;
                         "WHERE IncidentID = @original_IncidentID " &amp;
                         "AND ProductCode = @original_ProductCode " &amp;
                         "AND DateOpened = @original_DateOpened " &amp;
                         "AND (DateClosed = @original_DateClosed " &amp;
                         "OR DateClosed IS NULL " &amp;
                         "AND @original_DateClosed IS NULL) " &amp;
                         "AND Title = @original_Title " &amp;
                         "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
  </code></pre>