Gridview删除按钮不起作用

时间:2012-10-16 20:31:42

标签: gridview sqldatasource

我正在尝试使用网格视图使我的网页能够从管理页面编辑数据库(ImportantNews)。当我点击删除但它只刷新页面,不删除任何东西。我正在使用ASP.Net 2.0

的GridView

<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>
<br/>
<b>SqlDataSource</b>
<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>

我做了人们吮吸的并且得到了这个错误 必须声明标量变量&#34; @ Content&#34;。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:必须声明标量变量&#34; @ Content&#34;。

来源错误:

在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。

堆栈追踪:

[SqlException(0x80131904):必须声明标量变量&#34; @ Content&#34;。]    System.Data.SqlClient.SqlConnection.OnError(SqlException exception,Boolean breakConnection)+1953274    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,Boolean breakConnection)+4849707    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)+194    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)+2392    System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName,Boolean async)+192    System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result,String methodName,Boolean sendToPipe)+317    System.Data.SqlClient.SqlCommand.ExecuteNonQuery()+137    System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand命令,DataSourceOperation操作)+386    System.Web.UI.WebControls.SqlDataSourceView.ExecuteDelete(IDictionary keys,IDictionary oldValues)+303    System.Web.UI.DataSourceView.Delete(IDictionary keys,IDictionary oldValues,DataSourceViewOperationCallback回调)+89    System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row,Int32 rowIndex)+714    System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e,Boolean causeValidation,String validationGroup)+869    System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument)+207    System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)+10    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+13    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)+175    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+1565

1 个答案:

答案 0 :(得分:0)

尝试添加DataKeyNames =“内容”