Simple GridView Problem

T

Tina

I'm trying to do something very straightforward in a 2.0 asp.net app with a
GridView - ObjectDataSource - DataSet.

I create a DataSet that accesses the NorthWind Customers Table - all columns
and I choose to generate all methods and updates. I connect this DataSet to
an ObjectDataSource and connect my DataView to the ObjectDataSource. (I did
not opt for optimistic concurrency) It displays just fine. Then I try to
change an address field in a row and get the error pasted below. The update
command that was generated is also pasted below. This is stuff right out of
textbooks. What is wrong?

Thanks,
T

ObjectDataSource 'ods2' could not find a non-generic method 'Update' that
has parameters: CompanyName, ContactName, ContactTitle, Address, City,
Region, PostalCode, Country, Phone, Fax, original_CustomerID.


UPDATE Customers
SET CustomerID = @CustomerID, CompanyName = @CompanyName,
ContactName = @ContactName, ContactTitle = @ContactTitle, Address =
@Address,
City = @City, Region = @Region, PostalCode =
@PostalCode, Country = @Country, Phone = @Phone, Fax = @Fax
WHERE (CustomerID = @Original_CustomerID)
 
R

Ron

Tina said:
I'm trying to do something very straightforward in a 2.0 asp.net app with
a GridView - ObjectDataSource - DataSet.

I create a DataSet that accesses the NorthWind Customers Table - all
columns and I choose to generate all methods and updates. I connect this
DataSet to an ObjectDataSource and connect my DataView to the
ObjectDataSource. (I did not opt for optimistic concurrency) It displays
just fine. Then I try to change an address field in a row and get the
error pasted below. The update command that was generated is also pasted
below. This is stuff right out of textbooks. What is wrong?

Thanks,
T

ObjectDataSource 'ods2' could not find a non-generic method 'Update' that
has parameters: CompanyName, ContactName, ContactTitle, Address, City,
Region, PostalCode, Country, Phone, Fax, original_CustomerID.


UPDATE Customers
SET CustomerID = @CustomerID, CompanyName = @CompanyName,
ContactName = @ContactName, ContactTitle = @ContactTitle, Address =
@Address,
City = @City, Region = @Region, PostalCode =
@PostalCode, Country = @Country, Phone = @Phone, Fax = @Fax
WHERE (CustomerID = @Original_CustomerID)

Hi Tina.
The problem could be caused by an incorrect setting in your
ObjectDataSource.Have you made sure the ObjectDataSource is configured not
to send original values together with your own parameters?
The ObjectDataSource OldValuesParameterFormatString property should not be
set if you want to send only your own parameters.
HTH
Ron.
 
T

Tina

OldValuesParameterFormatString was set to Original_{0} so I set it to blank
and the same thing happens.
T
 
R

Ron

Tina said:
OldValuesParameterFormatString was set to Original_{0} so I set it to
blank and the same thing happens.
T
<snip>
OK, Tina.
Try removing the CustomerID = @CustomerID from your parameter list.
I wonder why you are using an ObjectDataSource and a DataSet when normally
an SqlDataSource works directly with a GridView. I set up an SqlDataSource
and a GridView to view and update the Northwind Customer Table without any
problem, but the Update SQL code in the SqlDataSource did not include a
CustomerID = @CustomerID, because CustomerID is the primary key of the
Customer table. So try changing your Update code to

UPDATE Customers
SET CompanyName = @CompanyName, ContactName = @ContactName,
ContactTitle = @ContactTitle, Address = @Address, City = @City, Region =
@Region, PostalCode = @PostalCode, Country = @Country, Phone = @Phone, Fax =
@Fax
WHERE (CustomerID = @Original_CustomerID)

You may have to change the WHERE clause to

WHERE (CustomerID = @CustomerID)

If that does not fix the problem, I suggest using an SqlDataSource instead
of the ObjectDataSource.

HTH

Ron.
 
Joined
Jun 22, 2007
Messages
1
Reaction score
0
Try deleting OldValuesParameterFormatString="original_{0}" from the ObjectDataSource tag.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top