查询表达式'#.42'中的日期语法错误。 c#winforms [英] Syntax error in date in query expression '#.42'. c# winforms
问题描述
尝试更新现有数据我使用了这个查询,但是在
top .ExecuteNonQuery();
查询表达式'#.42'中的日期语法错误。 这是我的查询这个查询有什么问题?帮助我。 Hi, Syntax error in date in query expression '#.42'. this is my query what was wrong with this query ?? help me.
这是我更新的sql查询
< pre lang =SQL> OleDbCommand top = new OleDbCommand( 更新NewInvoice_1 SET Terms =' + CBL_Terms.EditValue.ToString()+ ',
InvoiceDate =' + CBL_Date。文字 + ',
OurQuote =' + TXE_OurQuote。 Text + ',
SalesPerson =' + CBL_Sales_Person.EditValue.ToString()+ ',
Custo merName =' + CBL_Customer_Name.EditValue.ToString()+ ',
OrderNumber = ' + TXE_Order_Number。文本 + ',
InvoiceAddress =' + TXE_Invoice_Address。文字 + ',
DeliveryAddress = + TXE_Delivery_Address。 Text + ,
WholeDiscountP =' + 转换 .ToDecimal(TXE_FlatDiscountP。< span class =code-keyword> Text )+ ',
WholeDiscountA =' + 转换 .ToDecimal(TXE_FlatDiscountA。文字)+ ' ,
ShippingP =' + 转换 .ToDecimal(TXE_ShippingPercentage。文字) + ',
ShippingA =' + 转换 .ToDecimal(TXE_ShippingAmount。文本)+ ',
Price =' + 转换 .ToDecimal(TXE_SubTotal。 Text )+ ',
Discount =' + 转换 .ToDecimal(TXE_Discount。文本)+ ',
Tax =' + 转换 .ToDecimal(TXE_Tax。文字)+ ',
Shippi ng =' + 转换 .ToDecimal(TXE_Shipping。文本)+ ',
GrandTotal =' + 转换 .ToDecimal(TXE_GrandTotal。 Text )+ ',
TaxforDisc =' + barCheckItem1.Checked + ',
DiscountType = ' + selectedItem + ',
ShippingBy =' + TXE_Shipping_By 。文字 + ',
ShipReferenceNo = + TXE_Reference_No。文字 + ,
IsInsured =' + CBX_Is_Insured.Checked +
Notes =' + TXE_Notes。 Text + ',
DueDate =' + CBL_DueDate。文字 + 'WHERE InvoiceId = + TXE_Unvisible。 Text ,conn);
top .ExecuteNonQuery();
提前谢谢
Sri 几乎所有事情都有问题。您正在使用字符串连接,这使您的系统对SQL注入攻击保持开放。您使用
Convert.ToDecimal
内联,不允许无效条目。然后,您尝试将这些十进制值连接到您的字符串中。您应该使用正确的参数化查询并更正表格中每个字段的表示。
谢谢你的朋友,我解决了
< pre lang =SQL> OleDbCommand top = new OleDbCommand( 更新NewInvoice_1 SET +
Terms = + CBL_Terms。 EditValue.ToString()+ , +
InvoiceDate =' + CBL_Date。 DateTime + ', +
OurQuote =' + TXE_OurQuote。 Text + ', +
SalesPerson = + CBL_Sales_Person.EditValue.ToString()+ , +
CustomerName = + CBL_Customer_Name.EditValue.ToString()+ , +
OrderNumber =' + TXE_Order_Number。文本 + ', +
InvoiceAddress =' + TXE_Invoice_Address。文本 + ', +
DeliveryAddress =' + TXE_Delivery_Address。 Text + ', +
WholeDiscountP = + 转换 .ToDecimal(TXE_FlatDiscountP。文字)+ , +
WholeDiscountA = + 转换 .ToDecimal(TXE_FlatDiscountA。文字)+ , +
< span class =code-string> ShippingP = + 转换 .ToDecimal( TXE_ShippingPercentage。 文字)+ , +
ShippingA = + 转换 .ToDecimal(TXE_ShippingAmount。 Text )+ , +
Price = + 转换 .ToDecimal(TXE_SubTotal。文本)+ , +
Discount = + 转换 .ToDecimal(TXE_Discount。文本)+ , +
Tax = + 转换 .ToDecimal (TXE_Tax。 Text )+ , +
Shipping = + 转换 .ToDecimal(TXE_Shipping。 Text )+ , +
GrandTotal = + 转换 .ToDecimal(TXE_GrandTotal。文本)+ , +
TaxforDisc = + barCheckItem1.Checked + ,DiscountType =' + selectedItem + ', +
ShippingBy =' + TXE_Shipping_By。文字 + ',ShipReferenceNo =' + TXE_Reference_No。文本 + ', +
IsInsured = + CBX_Is_Insured.Checked + ,Notes =' + TXE_Notes。文本 + ', +
DueDate =' + CBL_DueDate。文字 + ' +
WHERE InvoiceId = + TXE_Unvisible。 Text ,conn);
top .ExecuteNonQuery();
An trying to update my existing data i used this query but am getting error on top.ExecuteNonQuery();
This is my updating sql query
OleDbCommand top = new OleDbCommand("UPDATE NewInvoice_1 SET Terms ='" + CBL_Terms.EditValue.ToString() + "',
InvoiceDate='" + CBL_Date.Text + "',
OurQuote='" + TXE_OurQuote.Text + "',
SalesPerson='" + CBL_Sales_Person.EditValue.ToString() + "',
CustomerName='" + CBL_Customer_Name.EditValue.ToString() + "',
OrderNumber='" + TXE_Order_Number.Text + "',
InvoiceAddress='" + TXE_Invoice_Address.Text + "',
DeliveryAddress=" + TXE_Delivery_Address.Text + ",
WholeDiscountP='" + Convert.ToDecimal(TXE_FlatDiscountP.Text) + "',
WholeDiscountA='" + Convert.ToDecimal(TXE_FlatDiscountA.Text) + "',
ShippingP='" + Convert.ToDecimal(TXE_ShippingPercentage.Text) + "',
ShippingA='" + Convert.ToDecimal(TXE_ShippingAmount.Text) + "',
Price='" + Convert.ToDecimal(TXE_SubTotal.Text) + "',
Discount='" + Convert.ToDecimal(TXE_Discount.Text) + "',
Tax='" + Convert.ToDecimal(TXE_Tax.Text) + "',
Shipping='" + Convert.ToDecimal(TXE_Shipping.Text) + "',
GrandTotal='" + Convert.ToDecimal(TXE_GrandTotal.Text) + "',
TaxforDisc='" + barCheckItem1.Checked + "',
DiscountType='" + selectedItem + "',
ShippingBy='" + TXE_Shipping_By.Text + "',
ShipReferenceNo=" + TXE_Reference_No.Text + ",
IsInsured='" + CBX_Is_Insured.Checked + "',
Notes='" + TXE_Notes.Text + "',
DueDate='" + CBL_DueDate.Text + "' WHERE InvoiceId=" + TXE_Unvisible.Text, conn);
top.ExecuteNonQuery();
Thanks in advance
SriJust about everything is wrong with it. You are using string concatenation which leaves your system wide open to SQL injection attacks. You are using
Convert.ToDecimal
inline, with no allowance for invalid entries. You are then trying to concatenate those decimal values into your string. You should use proper parameterised queries and correct representations of each field in your tables.Hi thanks you friends I solved
OleDbCommand top = new OleDbCommand("UPDATE NewInvoice_1 SET "+
" Terms = "+ CBL_Terms.EditValue.ToString() +", "+
" InvoiceDate='" + CBL_Date.DateTime + "', "+
" OurQuote='" + TXE_OurQuote.Text + "', "+
" SalesPerson=" + CBL_Sales_Person.EditValue.ToString() + ", "+
" CustomerName=" + CBL_Customer_Name.EditValue.ToString() + ", "+
" OrderNumber='" + TXE_Order_Number.Text + "', "+
" InvoiceAddress='" + TXE_Invoice_Address.Text + "', "+
" DeliveryAddress='" + TXE_Delivery_Address.Text + "', "+
" WholeDiscountP=" + Convert.ToDecimal(TXE_FlatDiscountP.Text) + ", "+
" WholeDiscountA=" + Convert.ToDecimal(TXE_FlatDiscountA.Text) + ", "+
" ShippingP=" + Convert.ToDecimal(TXE_ShippingPercentage.Text) + ", "+
" ShippingA=" + Convert.ToDecimal(TXE_ShippingAmount.Text) + ", "+
" Price=" + Convert.ToDecimal(TXE_SubTotal.Text) + ", "+
" Discount=" + Convert.ToDecimal(TXE_Discount.Text) + ", "+
" Tax=" + Convert.ToDecimal(TXE_Tax.Text) + ", "+
" Shipping=" + Convert.ToDecimal(TXE_Shipping.Text) + ", "+
" GrandTotal=" + Convert.ToDecimal(TXE_GrandTotal.Text) + ", "+
" TaxforDisc=" + barCheckItem1.Checked + ", DiscountType='" + selectedItem + "', "+
" ShippingBy='" + TXE_Shipping_By.Text + "',ShipReferenceNo='" + TXE_Reference_No.Text + "', "+
" IsInsured=" + CBX_Is_Insured.Checked + ", Notes='" + TXE_Notes.Text + "', "+
" DueDate='" + CBL_DueDate.Text + "' "+
" WHERE InvoiceId=" + TXE_Unvisible.Text, conn);
top.ExecuteNonQuery();
这篇关于查询表达式'#.42'中的日期语法错误。 c#winforms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!