运行MySql查询后出现缺少参数错误

发布于 2024-08-29 14:24:52 字数 3928 浏览 5 评论 0原文

我对 MySql 完全陌生,之前没有使用过带有 UpdateParameters 的 SqlDataSource,所以我可能错过了一些非常明显的东西。

当尝试更新记录时,更新确实发生,但随后抛出错误,指出“语句中缺少'id'参数”。因此查询有效并且数据库得到应有的更新,但随后会抛出错误。

这些是更新参数:

<UpdateParameters>
                <asp:Parameter Name="business_name" Type="string" Size="256" />
                <asp:Parameter Name="addr_line_1" Type="string" Size="256" />
                <asp:Parameter Name="addr_line_2" Type="string" Size="256" />
                <asp:Parameter Name="addr_line_3" Type="string" Size="256" />
                <asp:Parameter Name="postcode" Type="string" Size="32" />
                <asp:Parameter Name="county" Type="string" Size="128" />
                <asp:Parameter Name="town_city" Type="string" Size="256" />
                <asp:Parameter Name="tl_url" Type="string" Size="256" />
                <asp:Parameter Name="customer_id" Type="string" Size="16" />
                <asp:Parameter Name="region_id" Type="Int16" />
                <asp:Parameter Name="description" Type="string" Size="1024" />
                <asp:Parameter Name="approval_status" Type="string" Size="1" />
                <asp:Parameter Name="tl_user_name" Type="string" Size="256" />
                <asp:Parameter Name="phone"  Type="string" Size="50" />
                <asp:Parameter Name="uploaders_own" Type="Int16" />
            </UpdateParameters>

这是更新语句:

UPDATE myTable SET business_name = ?, addr_line_1 = ?, addr_line_2 = ?, addr_line_3 = ?, postcode = ?, county = ?, town_city = ?, tl_url = ?, customer_id = ?, region_id = ?, description = ?, approval_status = ?, tl_user_name = ?, phone = ?, uploaders_own = ? WHERE id = " + id

这是堆栈跟踪:

[InvalidOperationException: 'id' parameter is missing at the statement]
   CoreLab.MySql.r.a() +775
   CoreLab.MySql.r.a(Int32& A_0, ArrayList& A_1) +448
   CoreLab.MySql.x.e() +398
   CoreLab.MySql.x.o() +89
   CoreLab.MySql.MySqlCommand.a(CommandBehavior A_0, IDisposable A_1, Int32 A_2, Int32 A_3) +1306
   CoreLab.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior) +310
   System.Data.Common.DbCommand.ExecuteReader() +12
   CoreLab.Common.DbCommandBase.ExecuteNonQuery() +64
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +386
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +325
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
   System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation) +837
   System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +509
   System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +113
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.WebControls.LinkButton.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

有谁知道我做错了什么?

谢谢,

安妮莉

I'm completely new to MySql and haven't used SqlDataSource with UpdateParameters before, so I'm probably missing something very obvious.

When trying to update a record, the update does happen but then throws an error saying "'id' parameter is missing at the statement". So the query works and the database gets updated as it should, but an error is thrown afterwards.

These are the update parameters:

<UpdateParameters>
                <asp:Parameter Name="business_name" Type="string" Size="256" />
                <asp:Parameter Name="addr_line_1" Type="string" Size="256" />
                <asp:Parameter Name="addr_line_2" Type="string" Size="256" />
                <asp:Parameter Name="addr_line_3" Type="string" Size="256" />
                <asp:Parameter Name="postcode" Type="string" Size="32" />
                <asp:Parameter Name="county" Type="string" Size="128" />
                <asp:Parameter Name="town_city" Type="string" Size="256" />
                <asp:Parameter Name="tl_url" Type="string" Size="256" />
                <asp:Parameter Name="customer_id" Type="string" Size="16" />
                <asp:Parameter Name="region_id" Type="Int16" />
                <asp:Parameter Name="description" Type="string" Size="1024" />
                <asp:Parameter Name="approval_status" Type="string" Size="1" />
                <asp:Parameter Name="tl_user_name" Type="string" Size="256" />
                <asp:Parameter Name="phone"  Type="string" Size="50" />
                <asp:Parameter Name="uploaders_own" Type="Int16" />
            </UpdateParameters>

Here's the update statement:

UPDATE myTable SET business_name = ?, addr_line_1 = ?, addr_line_2 = ?, addr_line_3 = ?, postcode = ?, county = ?, town_city = ?, tl_url = ?, customer_id = ?, region_id = ?, description = ?, approval_status = ?, tl_user_name = ?, phone = ?, uploaders_own = ? WHERE id = " + id

Here's the stack trace:

[InvalidOperationException: 'id' parameter is missing at the statement]
   CoreLab.MySql.r.a() +775
   CoreLab.MySql.r.a(Int32& A_0, ArrayList& A_1) +448
   CoreLab.MySql.x.e() +398
   CoreLab.MySql.x.o() +89
   CoreLab.MySql.MySqlCommand.a(CommandBehavior A_0, IDisposable A_1, Int32 A_2, Int32 A_3) +1306
   CoreLab.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior) +310
   System.Data.Common.DbCommand.ExecuteReader() +12
   CoreLab.Common.DbCommandBase.ExecuteNonQuery() +64
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +386
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +325
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +92
   System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation) +837
   System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +509
   System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +95
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +113
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.WebControls.LinkButton.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

Does anyone know what I'm doing wrong?

Thanks,

Annelie

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪推晚风 2024-09-05 14:24:52

在查询的最后提到的 id 参数。
但似乎没有在某处定义

at the very end of your query id parameter mentioned.
but it doesn't seem to be defined somewhere

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文