Update Issue with a gridview

therookie32

Member
Joined
Jan 31, 2006
Messages
5
Programming Experience
Beginner
I have just been trying to use a dataset to populate a gridview and have a pretty standard table that i created for test purposes:
tblTest
TestID
TestName
StateID
PersonTypeID

The gridview populates properly with the adapter for it in my dataset and I created all the default commands for it but when I try to do an update with the gridview it is bound to I get this error:

Error Message:

ObjectDataSource 'TestDataset' could not find a non-generic method 'Update' that has parameters: TestName, StateID, PersonTypeID, original_TestID.

Code:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="TestID" DataSourceID="TestDataset">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="TestName" HeaderText="TestName" SortExpression="TestName" />
<asp:BoundField DataField="StateID" HeaderText="StateID" SortExpression="StateID" />
<asp:BoundField DataField="PersonTypeID" HeaderText="PersonTypeID" SortExpression="PersonTypeID" />
<asp:BoundField DataField="TestID" HeaderText="TestID" ReadOnly="True" SortExpression="TestID" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="TestDataset" runat="server" DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetTest" TypeName="AOATableAdapters.TestTableAdapter"
UpdateMethod="Update">
<DeleteParameters>
<asp:parameter Name="Original_TestID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="TestName" Type="String" />
<asp:parameter Name="StateID" Type="Int32" />
<asp:parameter Name="PersonTypeID" Type="Int32" />
<asp:parameter Name="TestID" Type="Int32" />
<asp:parameter Name="Original_TestID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="TestName" Type="String" />
<asp:parameter Name="StateID" Type="Int32" />
<asp:parameter Name="PersonTypeID" Type="Int32" />
<asp:parameter Name="TestID" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>

Update Command from Dataset:

UPDATE Test
SET TestName = @TestName, StateID = @StateID, PersonTypeID = @PersonTypeID, TestID = @TestID
WHERE (TestID = @Original_TestID)
 
Someone else solved this issue and their response was:

Remove the TestID field from the SET clause:

UPDATE Test
SET TestName = @TestName, StateID = @StateID, PersonTypeID = @PersonTypeID
WHERE (TestID = @Original_TestID)

Or set ReadOnly=false on the TestID column in the GridView:

<asp:BoundField DataField="TestID" HeaderText="TestID" ReadOnly="False" SortExpression="TestID" />
 
Indeed, updating the TestID is rather moot because you need to know what it is to select the row.. Did you write this SQL or did the IDE write it for you?
 
It does the same thing for me too :) - I frequently find myself rewriting the IDE standard queries :)
 
Back
Top