This is the error
“ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters...”
I figured it out for Gridview but not for FormView (my Gridview solution was to change ID field ReadOnly to False).
I tried to reduce this to a very simple test case and then apply some of the fixes posted around the web, but, so far, no joy.
Anyone that has VS2005/SQLExpress running can replicate this in a few minutes.
===============
My test procedure (I tried to make it as vanilla as possible)
If needed:
.1) Open a new website
.2) Add App_Code folder
.3) Create a new dataset, default name
.4) Add SQL DB to App_Data Folder
.5) Add Table to DB
SQL Table = aaaTest
===
ID int identity
Field1 varchar(50)
Field2 varchar(50)
===============
1) Open the Dataset Designer for the dataset
1.1) Drag table aaaTest table to the Dataset designer
2) Configure using the minimum number of key strokes (next, next, .finish)
3) Create Webform aaaTest
4) Drag on an ObjectDataSource
5) Point it at aaaTest TableAdapter
6) Configure with minimum key strokes (next, next, .. finish)
7) Drag on a FormView
5) Point it at the ObjectDataSource
6) Select "Enable Paging"
9) aaaTable is empty, so you won’t see a the FormView unless you do one of these
a) add a row to aaaTable from the Server explorer, or
b) Add this to the Page Code_Behind
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.FormView1.DefaultMode = FormViewMode.Insert
Exit Sub
End If
Me.FormView1.DefaultMode = FormViewMode.ReadOnly
End Sub
10) Run it
11) Test insert (DO A FEW inserts) -- OK
12) Test delete (But don’t delete your last record) – OK
13) (lucky number) Test edit - Get error:
ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters: Field1, Field2, original_ID.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="aaaTest.aspx.vb" Inherits="App_Pages_zzTest_aaaTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="APP_Maint_DSTableAdapters.aaaTestTableTableAdapter" UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Field1" Type="String" />
<asp:Parameter Name="Field2" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Original_ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Field1" Type="String" />
<asp:Parameter Name="Field2" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="ID"
DataSourceID="ObjectDataSource1">
<EditItemTemplate>
ID:
<asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
Field1:
<asp:TextBox ID="Field1TextBox" runat="server" Text='<%# Bind("Field1") %>'>
</asp:TextBox><br />
Field2:
<asp:TextBox ID="Field2TextBox" runat="server" Text='<%# Bind("Field2") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
<InsertItemTemplate>
Field1:
<asp:TextBox ID="Field1TextBox" runat="server" Text='<%# Bind("Field1") %>'>
</asp:TextBox><br />
Field2:
<asp:TextBox ID="Field2TextBox" runat="server" Text='<%# Bind("Field2") %>'>
</asp:TextBox><br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
Text="Insert">
</asp:LinkButton>
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</InsertItemTemplate>
<ItemTemplate>
ID:
<asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
Field1:
<asp:Label ID="Field1Label" runat="server" Text='<%# Bind("Field1") %>'></asp:Label><br />
Field2:
<asp:Label ID="Field2Label" runat="server" Text='<%# Bind("Field2") %>'></asp:Label><br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
Text="Edit">
</asp:LinkButton>
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete">
</asp:LinkButton>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
Text="New">
</asp:LinkButton>
</ItemTemplate>
</asp:FormView>
</form>
</body>
</html>
----------------------------------------------------------------
Here’s the tableadapter update query
UPDATE [dbo].[aaaTestTable] SET [Field1] = @Field1, [Field2] = @Field2 WHERE (([ID] = @Original_ID));
SELECT ID, Field1, Field2 FROM aaaTestTable WHERE (ID = @ID)
-------------------------------------------------------------
As I mentioned, I tried several combinations of changes based on suggestions from posts here and elsewhere, and could not get it to work.
I can play with the code I can see, but since I’m functionally a “hobby programmer” I don’t have a lot of theory of internals to work with.
Any help with getting this to work would be appreciated. Pre-tested solutions would be much preferred, of course, since I've tried lots of combinations already. I'll keep researching and experimenting in any case.
If I find an answer I will definitely post it back here.
Thanks!