.net使用GridView控件删除时提示必须声明标量变量 "@id",而修改时正常。
代码:<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataSourceID="...
代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource_khrywh" DataKeyNames="id">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" />
<asp:BoundField DataField="ni" HeaderText="年" SortExpression="ni" />
<asp:BoundField DataField="yue" HeaderText="月" SortExpression="yue" />
<asp:BoundField DataField="zm" HeaderText="职名" SortExpression="zm" />
<asp:BoundField DataField="xm" HeaderText="姓名" SortExpression="xm" />
<asp:CommandField ShowDeleteButton="True" HeaderText="删除" />
<asp:CommandField ShowEditButton="True" HeaderText="编辑" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource_khrywh" runat="server"
ConnectionString="<%$ ConnectionStrings:highConnectionString %>"
SelectCommand="SELECT id,ni,yue,zm,xm FROM [lwxx_ksgbmc] WHERE (([ni] = @ni) AND ([yue] = @yue)) order by [xh]"
DeleteCommand="delete from [lwxx_ksgbmc] where ([id]=@id)"
UpdateCommand="update [lwxx_ksgbmc] set zm=@zm,xm=@xm where ([id]=@id)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="ni" PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="DropDownList2" Name="yue" PropertyName="SelectedValue" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
[SqlException (0x80131904): 必须声明标量变量 "@id"。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +212
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2811
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +3041999
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +470
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +182
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +2782310
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +4052080
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +1050
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +482
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +215
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981 展开
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource_khrywh" DataKeyNames="id">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" />
<asp:BoundField DataField="ni" HeaderText="年" SortExpression="ni" />
<asp:BoundField DataField="yue" HeaderText="月" SortExpression="yue" />
<asp:BoundField DataField="zm" HeaderText="职名" SortExpression="zm" />
<asp:BoundField DataField="xm" HeaderText="姓名" SortExpression="xm" />
<asp:CommandField ShowDeleteButton="True" HeaderText="删除" />
<asp:CommandField ShowEditButton="True" HeaderText="编辑" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource_khrywh" runat="server"
ConnectionString="<%$ ConnectionStrings:highConnectionString %>"
SelectCommand="SELECT id,ni,yue,zm,xm FROM [lwxx_ksgbmc] WHERE (([ni] = @ni) AND ([yue] = @yue)) order by [xh]"
DeleteCommand="delete from [lwxx_ksgbmc] where ([id]=@id)"
UpdateCommand="update [lwxx_ksgbmc] set zm=@zm,xm=@xm where ([id]=@id)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="ni" PropertyName="SelectedValue" Type="Decimal" />
<asp:ControlParameter ControlID="DropDownList2" Name="yue" PropertyName="SelectedValue" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
[SqlException (0x80131904): 必须声明标量变量 "@id"。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +212
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +245
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2811
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +3041999
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +470
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +182
System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +2782310
System.Web.UI.DataSourceView.Delete(IDictionary keys, IDictionary oldValues, DataSourceViewOperationCallback callback) +4052080
System.Web.UI.WebControls.GridView.HandleDelete(GridViewRow row, Int32 rowIndex) +1050
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +482
System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument) +215
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981 展开
3个回答
展开全部
遇到这种问题一般是有变量id,但是没有传参,建议还是建立断点调试一下
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看一下GridView里绑定DataSourceID你确定是SqlDataSource_khrywh??
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在数据库里运行 sql语句 看看是否有 主外键关系
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询