TableAdapter Update Error

I made a TableAdapter and use ObjectSource to bind it to GridView, when I insert new rows it works OK, but when I try to Update or Delete it gives me this error:

ObjectDataSource 'RegionObject' could not find a non-generic method 'Update' that has parameters: RegionDescription, original_RegionID.

Version Information: Microsoft .NET Framework Version:2.0.50215.44; ASP.NET Version:2.0.50215.44
Thanks

Alaa Bhr
Software Developer

[3003 byte] By [dida] at [2008-2-4]
# 1
Hi,
Could you check your *.xsd file? See if the update queries available in your tableadapter has these kind of arguments. If not try creating it...

cheers,
Paul June A. Domag

PaulDomag at 2007-9-7 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
I have the same error. I have used the ObjectDataSource from the .xsd file. My GridView displays the data (and only the fields from the .xsd file.). The delete operation works. however, the Update fails with the same type of error message. All the parameters are what is used in the stored procdure.

Is there some oddity with this April CPT version of visual web developer 2005 Express?

Any thoughts are appreciated.

thank you,
chuck

crbeckman at 2007-9-7 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3
Alaa,

Could you provide steps to reproduce this behavior? That should make it easier to get a helpful response.

David Sceppa
Microsoft

DavidSceppa at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 4
Here is my process: (all with visual web developer 2005 Express, April version.)

1. create new dataset in the app_code folder, called interaction.xsd. (right-click on the app_code directory and select new...)

a. Step through the TableAdapter Configuration Wizard.
b. Select the data connection (ManagementConnection String (Web.config)
c. Create new stored procedures
d. sql statement "SELECT Interaction.* FROM Interaction
e. new stored procedure names: InteractionSelect_sp, InteractionInsert_sp, InteractionUpdate_sp, InteractionDelete_sp
f. Fill method: FillInteraction, Get method: GetInteraction
g. Checked Create methods to send updates directly...
h. I now have Interaction.xsd.

2. Create new content page (code in separate file (Visual Basic) and uses master page), called Interaction.aspx.

3. In Design view, drag an ObjectDataSource onto the page.

a. (Configure Data Source) Selected InteractionTableAdapters.InteractionSelect_spTableAdapter.
b. Select method: GetInteraction(), return...
c. Update method: Update(Nullable<INT32> iFirmID, ... (Each field in the Interaction table is listed, as well as "Original_iInteractionID, Int32".)
d. Insert method: Insert(Nullable(int32> iFirmID,...(again, each field in the Interaction table is listed.)
e. Delete method: Delete(Int32 Original_iTransactionID), returns Int32

4. Drag a Gridview object onto the page.

a. Choose Data Source - ObjectDataSource1 selected.
b. Select "Enable Editing" and "Enable Deleting" also for the Gridview.

5. ctl-F5, select the page from the page navigation. Data is pulled from the database and is correct. Click on the Edit link, click on the update link.

6. Get the non-generic method error.

What am I doing wrong? What step am I missing?

chuck

crbeckman at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 5
Aala, (I hope I spelled that correctly). After beating my head against the wall for nearly a week and then seeing your post, I realized that I probably was not the only one with this issue. I simply switched from an ObjectDataSource to an SqlDataSource and my edits and deletes in the GridView work just fine. Having not heard anything from the experts here (or in the Visual Studio Express forum), I suspect there is a problem with the ODS vice the SDS processes, people have realized it and either are using a workaround or switched to the SqlDataSource.

Best wishes,
chuck

crbeckman at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 6

Dear David,
Here are my process in details (all the details Big Smile)
1-Create new web site
2-Add App_Code folder
3-Add new DataSet under the App_Code folder
4-Add new DataAdapter
5-Select Region table "from Northwind"
6-Select Create new SP
7-Check Create method to send updates directly to database
8-Unchek FillData
9-Check GetData
10-Add GridView to the form
11-Choose <New DataSource> ObjectDataSource
12-Configure it as following:
- Select: GetRegions() returns RegionsDataTable
- Update: Update(Int32 RegionID, String RegionDescription, Int32 Original_RegionID), returns Int32
- Delete: Delete(Int32 Original_RegionID), returns Int32
13-Enable the GridView Editding, Deleting and Paging
14-Run the application
15-Try to Edit got:
ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters: RegionDescription, original_RegionID.
16-Try to Delete:
It delete Normaly

dida at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 7
Dear Chuck,
My name is Alaa, any way I think I made it I add my own Update method and use it and it ran normaly. But I still don't know why it make this behavior with the genrated Update method.

Best regards,
Alaa Bhr

dida at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 8
The problem in this case is that your Update method takes three params: RegionID, RegionDescription, and Original_RegionID but only two params are passed to the data source by the data-bound control: RegionDescription and Original_RegionID. I suspect you need to set ReadOnly=false on the RegionID column in the GridView, so that a new value is passed to the data source for this column. Alternatively, if you do not want to support editing the primary key (RegionID), then alter your Update statement so that it does not expect this value.

Hope this helps,
Bradley Millington
Web Platform and Tools Team, Microsoft

Bradley at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 9
David,

Just to elaborate on Bradley's post...to resolve the "could not find non-generic method" error when using a generated DataSet with the ObjectDataSource, you should to the following to modify the generated Update method on the tablenameDataAdapter in the DataSet (where tablename is the name of the table you're pulling from the database):

1. Open the DataSet in Visual Studio 2005 and highlight the tablenameDataAdapter title bar.

2. If you don't already have the Properties window open, press F4 to open it, and locate the UpdateCommand item.

3. Click the + sign next to UpdateCommand to expand the individual properties.

4. Edit the CommandText to remove the primary key column from the query.

This should resolve the mismatch between the DataAdapter and the data-bound control.

G.AndrewDuthie at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 10
Bradley wrote:
The problem in this case is that your Update method takes three params: RegionID, RegionDescription, and Original_RegionID but only two params are passed to the data source by the data-bound control: RegionDescription and Original_RegionID. I suspect you need to set ReadOnly=false on the RegionID column in the GridView, so that a new value is passed to the data source for this column. Alternatively, if you do not want to support editing the primary key (RegionID), then alter your Update statement so that it does not expect this value.

Hope this helps,
Bradley Millington
Web Platform and Tools Team, Microsoft

I think there is more to this problem than just a mismatch between parameters in ObjectDataSource and the TableAdapter. The ObjectDataSource is automatically adding on parameters. I am getting the following error:

ObjectDataSource 'odsIAF' could not find a non-generic method 'Update' that has parameters: Status, RecDivision, RecLocation, RecContact, RecAddress, RecPhone, RecFax, ProDivision, ProLocation, ProContact, ProAddress, ProPhone, ProFax, original_ID, ID, DateEntered.

Neither ID or DateEntered are defined in the TableAdapter's UpdateCommand CommandText or Parameters. They are not defined in the ObjectDataSource's UpdateParameters. They are being returned by the select. Something is causing them to be automatically tacked onto the end.

MichaelJozwik at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 11
Andrew,

I also had to then go and edit my g_UpdateTable stored procedure to remove the extra column too.

Kevin

KevinSchlegelmilch at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 12
hello world
raymondS1221 at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 13
A simple but kludge would be to make column with PK not ReadOnly, switch it to a template column and add onBlur. This would allow all the design surface wizard to still work without delving into code too much.

OnFocus="this.blur();"

change

<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" SortExpression="EmployeeID" />

to

<asp:TemplateField HeaderText="EmployeeID" SortExpression="EmployeeID">

<EditItemTemplate>

<asp:TextBox ID="TextBox1" OnFocus="this.blur();" runat="server" Text='<%# Bind("EmployeeID") %>'></asp:TextBox>

</EditItemTemplate>

<InsertItemTemplate>

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("EmployeeID") %>'></asp:TextBox>

</InsertItemTemplate>

<ItemTemplate>

<asp:Label ID="Label1" runat="server" Text='<%# Bind("EmployeeID") %>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>

JimHomminga at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 14
Hi Andrew,


I followed the steps you suggested but I still got the error.

I noticed that under the UpdateCommand, there is a Parameters collection.

I opened it and the primary key column is also defined there!

I remove it and its working now.

Thanks for pointing the right direction!

ghelobytes at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...