views:

110

answers:

1

Hello,

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

+1  A: 

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

Col. Shrapnel
Sorry, that's me snipping just core bits of code in there. The id is defined earlier, and when stepping through I can see it's the id I'm expecting (and the correct record does get updated in the database, the error happens after that).
annelie
@annelie I have no idea of ASP, but probably you have to use id the same way as other parameters, by using `?` mark
Col. Shrapnel
Thanks, that seems to do the trick! The id is passed in the above way for the select query which works fine, so I assumed I had to pass in the id the same way for the update as well but apparently not. Thank you so much for your help!
annelie