I have a dataset that points to a View in my SQL database, and a gridview that uses this dataset to populate itself. I of course want the rows editable, so I added Edit and Delete functionality to the gridview - standard method (not custom buttons)
working with the Update Query now... For some reason it didn't auto-generate the update statement (Probably cause the dataset points to a view rather than a table i'm guessing) so I have to create it myself. No problem - I select the dataset, choose properties, and choose UpdateQuery.
Here is my query:
UPDATE dbo.tblHardware SET TypeID = @TypeID, Name = @Name, Description = @Description, Cost = @Cost, Weight = @Weight, Image = @Image WHERE (HardwareID = @HardwareID)
The parameter source is set to "Form" and I have the name of each parameter listed.
Here is the relevant code from the aspx page:
<asp:SqlDataSource ID="dsHardware" runat="server"
ConnectionString="<%$ ConnectionStrings:RequestFormsConnectionString %>"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [vHardware]"
UpdateCommand="UPDATE dbo.tblHardware SET TypeID = @TypeID, Name = @Name, Description = @Description, Cost = @Cost, Weight = @Weight, Image = @Image WHERE (HardwareID = @HardwareID)"
InsertCommand="INSERT INTO [vHardware] ([HardwareID], [TypeID], [Description], [Name], [Cost], [Weight], [Image], [TypeDesc], [TypeName], [TypeTypeID]) VALUES (@HardwareID, @TypeID, @Description, @Name, @Cost, @Weight, @Image, @TypeDesc, @TypeName, @TypeTypeID)"
DeleteCommand="DELETE From tblHardware WHERE HardwareID = @HardwareID">
<UpdateParameters>
<asp:FormParameter FormField="TypeID" Name="TypeID" />
<asp:FormParameter FormField="Name" Name="Name" />
<asp:FormParameter FormField="Description" Name="Description" />
<asp:FormParameter FormField="Cost" Name="Cost" />
<asp:FormParameter FormField="Weight" Name="Weight" />
<asp:FormParameter FormField="Image" Name="Image" />
<asp:FormParameter FormField="HardwareID" Name="HardwareID" />
</UpdateParameters>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataKeyNames="HardwareID,TypeTypeID"
DataSourceID="dsHardware">
<Columns>
<asp:BoundField DataField="HardwareID" HeaderText="HardwareID" InsertVisible="False"
ReadOnly="True" SortExpression="HardwareID" />
<asp:BoundField DataField="TypeID" HeaderText="TypeID" SortExpression="TypeID" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" />
<asp:BoundField DataField="Weight" HeaderText="Weight" SortExpression="Weight" />
<asp:BoundField DataField="Image" HeaderText="Image" SortExpression="Image" />
<asp:BoundField DataField="TypeDesc" HeaderText="TypeDesc" SortExpression="TypeDesc" />
<asp:BoundField DataField="TypeName" HeaderText="TypeName" SortExpression="TypeName" />
<asp:BoundField DataField="TypeTypeID" HeaderText="TypeTypeID" InsertVisible="False"
ReadOnly="True" SortExpression="TypeTypeID" />
</Columns>
</asp:GridView>
So how is this all supposed to work? Apologies I am new to ASP.NET - previous classic ASP developer.
EDIT: Sorry I should be more clear. When attempting an Update, I receive the error "@Hardware needs to be defined". Not sure why as it looks plenty defined to me. Also, there is NO code in my .cs file - I assume I need something there, but not sure what exactly.