[英]Syntax error (missing operator) in query expression '05-04-2014 AM 12:00:00' C#?
AM trying to update the date in that query am getting this error Syntax error in UPDATE statement., this is my code我正在尝试更新该查询中的日期,但在 UPDATE 语句中出现此错误语法错误。这是我的代码
Updated Code
OleDbCommand top = new OleDbCommand(
"UPDATE NewInvoice_1 SET (" +
"Terms=?, [InvoiceDate]=?, OurQuote=?," +
"SalesPerson=?, CustomerName=?, OrderNumber=?," +
"InvoiceAddress=?, DeliveryAddress=?," +
"WholeDiscountP=?, WholeDiscountA=?, ShippingP=?, ShippingA=?," +
"Price=?, Discount=?, Tax=?," +
"Shipping=?, GrandTotal=?, TaxforDisc=?, DiscountType=?," +
"ShippingBy=?, ShipReferenceNo=?, IsInsured=?, Notes=?," +
"[DueDate]=?, AmountinWords=? ) WHERE InvoiceId=?", conn);
top.Parameters.AddWithValue("?", CBL_Terms.EditValue.ToString());
top.Parameters.AddWithValue("?", CBL_Date.DateTime);
top.Parameters.AddWithValue("?", TXE_OurQuote.Text);
top.Parameters.AddWithValue("?", CBL_Sales_Person.EditValue.ToString());
top.Parameters.AddWithValue("?", CBL_Customer_Name.EditValue.ToString());
top.Parameters.AddWithValue("?", TXE_Order_Number.Text);
top.Parameters.AddWithValue("?", TXE_Invoice_Address.Text);
top.Parameters.AddWithValue("?", TXE_Delivery_Address.Text);
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_FlatDiscountP.Text));
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_FlatDiscountA.Text));
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_ShippingPercentage.Text));
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_ShippingAmount.Text));
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_SubTotal.Text));
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_Discount.Text));
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_Tax.Text));
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_Shipping.Text));
top.Parameters.AddWithValue("?", Convert.ToDecimal(TXE_GrandTotal.Text));
top.Parameters.AddWithValue("?", barCheckItem1.Checked);
top.Parameters.AddWithValue("?", selectedItem);
top.Parameters.AddWithValue("?", TXE_Shipping_By.Text);
top.Parameters.AddWithValue("?", TXE_Reference_No.Text);
top.Parameters.AddWithValue("?", CBX_Is_Insured.Checked);
top.Parameters.AddWithValue("?", TXE_Notes.Text);
top.Parameters.AddWithValue("?", CBL_DueDate.DateTime);
top.Parameters.AddWithValue("?", TXE_AmountinWords.Text);
top.Parameters.AddWithValue("?", TXE_Unvisible.Text);
top.ExecuteNonQuery();
Now I update my code to parameters but getting Syntax error on updating code现在我将代码更新为参数,但在更新代码时出现语法错误
Use parameters.使用参数。 Put ?放 ? for every parameter value.对于每个参数值。 Use same order when adding parameter values.添加参数值时使用相同的顺序。
string sql = "UPDATE NewInvoice_1 SET Terms =?, [InvoiceDate]=?, OurQuote=? ... WHERE InvoiceId=?";
using (var command = conn.CreateCommand())
{
command.CommandText = sql;
command.Parameters.Add(CBL_Terms.EditValue.ToString());
command.Parameters.Add(CBL_Date.DateTime);
command.Parameters.Add(TXE_OurQuote.Text);
//add all other fields keeping order
command.ExecuteNonQuery();
}
Side note - you shouldn't really execute or keep queries in a form.旁注 - 您不应该真正执行或保留表单中的查询。 Also, if you use adapter, you could use below syntax to add parameters:此外,如果您使用适配器,您可以使用以下语法添加参数:
command.Parameters.Add(adapter.Parameter(value));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.