Software is not Jewellery

Computers should help us concentrate on our work, without concentrating on the computer – Benjamin B. Bederson

Archive for the ‘ASP .NET’ Category

ObjectDataSource: could not find a non-generic method ‘Update’. Problems using ASP .NET 2.0 DeatilsView and TableAdapter

without comments

Note: This problem is resolved in Visual Studio 2005 SP1 and Visual Web Developer 2005 Express Edition SP1. Try installing the service packs to get around this problem. Or you could just download Visual Web Developer 2008 Express!

Using .NET 2.0 TableAdapters wizard and ASP.NET 2.0 DetailsView data source configuration causes many problems including a runtime error during update or a failure to update the data. Many users have reported this error. A little bit of Googling helped me find out that this error is because a mismatch in the parameters generated by the TableAdapter and the DetailsView for the update command. Here is a way that I used to solve this. I did not find anyone writing about this technique. So I thought I might as well write it here.

How to Reproduce the error?

You should be using Visual Studio 2005(ASP.NET 2.0) and SQL Express. I don’t know if this problem exists with SQL Server as well. I haven’t tried it.

1. Create a table in SQL Express or SQL Server. The table should have an Identity field.

2. Add a Dataset to the Project.

3. Drag and drop the table from VS 2005’s Server Explorer to the Dataset. This creates a DataTable along with a TableAdapter. Note the TableAdapter has a Fill Query, and Delete, Insert, Select and Update Command. The Update Command is not generated if the table does not contain an Identity field. Alternatively you can add a TableAdapter to the dataset and configure the table adapter using the TableAdapter Wizard.

4. Add an ASPX file to the project. Add a DetailsView to this file. From the DetailsView Tasks (that shows up on clicking the arrow mark on the right top of the details view in the designer mode) select the TableAdapter as the datasource. Enable Paging, Inserting, Editing and Deleting.

5. Run the Page. Try Updating. You should either get a runtime error or the update just doesn’t work.

If you are getting either of these, read on.

How to fix the problem?

1. Create a Table in the SQL Express. Make sure it has and Identity field and all other field have “allow nulls” as true. You may change it later but you need to have it enabled while generating the TableAdapter. Here I have used three fields id, Name, Type

2. Create a dataset. Drag and drop the table from the server explorer to the xsd file.

3. Right click on the TableAdapter and go to properties. Expand UpdateCommand click on the Paratemetrs. Remove all ISNull_and Original except Original_ID.

4. Open CommandText and remove text after WHERE (id=@Original_id). Save the XSD file.

5. Create a DetailsView in an ASPX file and slect the TableAdapter as datasource. Enable Paging, Inserting, Editing and Deleting.

6. Click on the edit fields of the DetailsView and Make the ReadOnly property of Id field as False. You can change it to ReadOnly = True later.

7. Run the aspx file. Things work just fine.

Hopefully this helps.

Written by Abhishek

April 22, 2008 at 4:24 pm

Posted in ASP .NET