deletecommand problem

Don
Joined
5 Oct 2005
Posts
11,239
Location
Liverpool
I have this...
<form id="form1" runat="server">
<div>
<asp:GridView ID="AdminGridView" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" DataSourceID="EventDataSource">
<Columns>
<asp:BoundField DataField="PriKey" HeaderText="ID No" />
<asp:BoundField DataField="Typage" HeaderText="Type" />
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="BookedFrom" HeaderText="From" />
<asp:BoundField DataField="BookedUntill" HeaderText="Untill" />
<asp:BoundField DataField="Setup" HeaderText="Set Up?" />
<asp:BoundField DataField="TimeStamp" HeaderText="Time Stamp" />
<asp:BoundField DataField="Approved" HeaderText="Approved?" />
<asp:BoundField DataField="ModelNo" HeaderText="Model No" />
<asp:BoundField DataField="Projector" HeaderText="Projector" />
<asp:BoundField DataField="Status" HeaderText="Status" />
<asp:BoundField DataField="AssignedBy" HeaderText="AssignedBy" />
<asp:BoundField DataField="BookedIn" HeaderText="Booked In" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton ="True" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
<asp:SqlDataSource ID="EventDataSource" runat="server" ConnectionString="<%$ appsettings:ConnectionString %>"
SelectCommand="SELECT * FROM [book]" DeleteCommand="DELETE FROM [book] WHERE ([PriKey] = @PriKey)" InsertCommand="INSERT INTO [Events] ([PriKey], [Typage], [Username], [BookedFrom], [BookedUntill], [SetUp], [TimeStamp], [Approved], [ModelNo], [Projector], [Status], [AssignedBy], [BookedIn]) VALUES (@PriKey, @Typage, @username, @BookedFrom, @BookedUntill, @SetUp, @Approved, @ModelNo, @Projector, @Status, @AssignedBy, @BookedIn)" UpdateCommand="UPDATE [book] SET [PriKey] = @PriKey, [Typage] = @Typage, [Username] = @username, [BookedFrom] = @BookedFrom, [BookedUntill] = @BookedUntill, [SetUp] = @SetUp, [TimeStamp] = @TimeStamp, [Approved] = @Approved, [ModelNo] = @ModelNo, [Projector] = @Projector, [Status] = @Status, [AssignedBy] = @AssignedBy, [BookedIn] = @BookedIn WHERE [PriKey] = @PriKey">
<DeleteParameters>
<asp:Parameter Name="PriKey" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="PriKey" Type="Int32" />
<asp:Parameter Name="Typage" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="BookedFrom" Type="String" />
<asp:Parameter Name="BookedUntill" Type="String" />
<asp:Parameter Name="SetUp" Type="String" />
<asp:Parameter Name="TimeStamp" Type="String" />
<asp:Parameter Name="Approved" Type="String" />
<asp:Parameter Name="ModelNo" Type="String" />
<asp:Parameter Name="Projector" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="AssignedBy" Type="String" />
<asp:Parameter Name="BookedIn" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="PriKey" Type="Int32" />
<asp:Parameter Name="Typage" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="BookedFrom" Type="String" />
<asp:Parameter Name="BookedUntill" Type="String" />
<asp:Parameter Name="SetUp" Type="String" />
<asp:Parameter Name="TimeStamp" Type="String" />
<asp:Parameter Name="Approved" Type="String" />
<asp:Parameter Name="ModelNo" Type="String" />
<asp:Parameter Name="Projector" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="AssignedBy" Type="String" />
<asp:Parameter Name="BookedIn" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>

and its not deleting throwing this up...

Must declare the scalar variable "@PriKey".
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@PriKey".

Source Error:

cheers in advance

Stelly
 
figured it out lads... silly me

Code:
<asp:GridView ID="AdminGridView" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" DataSourceID="EventDataSource">

should be

Code:
<asp:GridView ID="AdminGridView" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" DataSourceID="EventDataSource" DataKeyNames="PriKey">

Mr B Gates said:
Gets or sets an array that contains the names of the primary key fields for the items displayed in a GridView control
need to set the primarykey in the gridview... oops!

Thanks anyway :)

Stelly
 
Back
Top Bottom