Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
An trying to update my existing data i used this query but am getting error on
SQL
top.ExecuteNonQuery();
Syntax error in date in query expression '#.42'.
This is my updating sql query
SQL
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();
this is my query what was wrong with this query ?? help me.
Thanks in advance
Sri
Posted

Just 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.
 
Share this answer
 
Hi thanks you friends I solved

SQL
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();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900