简体   繁体   English

查询表达式 '05-04-2014 AM 12:00:00' C# 中的语法错误(缺少运算符)?

[英]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.

相关问题 在C#中将格式为12 hour(04/29/2013 10:00:00 AM)的字符串转换为日期时间 - Convert string with format 12 hour(04/29/2013 10:00:00 AM) to datetime in C# 如何将 String string dataReturned = "62 07 00 00 04 05 00 01 A0" 转换为 List<byte> 在 C#</byte> - How to convert String string dataReturned = "62 07 00 00 04 05 00 01 A0" to List<byte> in C# 查询表达式中的C#语法错误(缺少运算符) - C# Syntax error (missing operator) in query expression C#查询表达式中的语法错误(缺少运算符) - Syntax error (missing operator) in query expression in C# 在C#中的查询表达式中获取语法错误(缺少运算符) - Getting a syntax error (missing operator) in query expression in C# 查询表达式c#中的语法错误(缺少运算符) - Syntax error (missing operator) in query expression c# 如何使用DataContractJsonSerializer将“12/19/2013 12:00:00 AM”序列化为C#上的DateTime类型 - How to serialize “12/19/2013 12:00:00 AM” to DateTime Type on C# using DataContractJsonSerializer 添加日期,但在c#中给我12:00 AM - Add months on date but gives me 12:00 AM in c# 离开日期时间选择器在C#中返回1/1/0001 12:00:00 AM - leave datetime picker returns 1 / 1 / 0001 12:00:00 AM in c# C#FTP Response.LastModified始终返回1/1/0001 12:00:00 AM - C# FTP Response.LastModified always returns 1/1/0001 12:00:00 AM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM