Я пытаюсь включить удаление в виде сетки. Когда вы запускаете этот код и нажимаете кнопку удаления, вы получаете сообщение об ошибке. Необходимо объявить скалярную переменную «@Content».
Код
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Content" HeaderText="Content" SortExpression="Content" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [ImportantNews]"
DeleteCommand="DELETE FROM [ImportantNews] WHERE [Content] = @Content AND [Title] = @Title">
<DeleteParameters>
<asp:Parameter Name="Title" Type="string"/>
<asp:Parameter Name="Content" Type="string"/>
</DeleteParameters>
</asp:SqlDataSource>
Обратите внимание, что я использую Asp.net 2.0.