ObjectDataSource and Primary Key on DB Table

G

Guest

Environment:
XP sp2
VS.Net 2005 (Asp.Net 2.0 - c#)
Sql Server 2005

Scenario:
-Table (Table1) with two columns:
Table1Id <- Primary Key
Column1

-Standard CRUD stored procs; no fancy busines logic, just straight CRUD
actions
-The update sp updates Column1 where Table1Id = @Table1ID (Table1Id is not
updated).

In VS.Net 2005:
-Create a Typed DataSet (DataSet1) against Table1 and the stored procs
-Add WebForm1.aspx
-Drag on a GridView and bind it to DataSet1 for listing with and
ObjectDataSource (ObjectDataSource1)
-Drag on a FormView and bind it to DataSet1 for selected record retrieval
and updating with another ObjectDataSource (ObjectDataSource2)

Issue:
When I try to update the record I get the ...ObjectDataSource
'ObjectDataSource2' could not find a non-generic method 'Update' that has
parameters:... error. The primary key field (Table1Id) is being excluded
from the parameter list in the update attempt. The field in is shown to be
in typed dataset and both objectdatasources. I am NOT displaying Table1Id in
the gridview or the formview, but I am specifiing Table1Id as a DataKeyName
in GridView1. I've seen references to this error and scenario of missing the
primary key field all over the web. Apparently it is related to that fact
that the Primary Key field is not updated, so the update call excludes this
field. That doesn't match the update schema in the data set, so an error is
thrown. Usually the issue is resolved by making the Primary Key field
readonly=false in the GridView, but as I said, I'm not displaying the Primary
Key field.

As well, I can remove the Primary Key property from the table in the DB and
following the exact same setup and development procedure and everything works
fine.

It seems like a fairly common procedure to have a Primary Key field set in
the DB and a table updated on that field, so how do I make it work in VS.Net?
Is there a property I'm seeing that needs set? I essentially understand
what is happening, but I have trouble excepting the fact that I have to
remove and readd PK's for my tables as I'm developing the site against the DB.

Thanks.
 

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,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top