Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this query was completely gave output when I used sql database,but with access this give error that is "Syntax error in UPDATE statement"

SQL
"update Client_Payment_TB set Pay_Mode ='" + Pay_Modes.ToString() + "', Cheque_DD_No ='" + txt_Chaque_No.Text + "', Bank ='" + txt_Bank.Text + "', Cheque_Date ='" + dateTimePicker_Chaque.Value.ToString("dd/MM/yyyy") + "', Current_Date ='" + dateTimePicker_Current_date.Value.ToString("dd/MM/yyyy") + "', Discount_Amount ='" + txt_Discount.Text + "', Paid ='" + dpp.ToString() + "', Remaining='" + txt_Remaining.Text + "' where Bill_ID='" + txt_Bill_No.Text + "'";


Please help me....!!
Posted
Updated 22-Oct-13 1:25am
v2
Comments
ZurdoDev 22-Oct-13 7:33am    
Yes, Access has slightly different syntax. I would recommend searching for examples of updates statements. As I recall, dates get a # around it, as one of the differences.

First off, Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
The chances are that fixing that will get rid of your problem anyway!

C#
string sql = "UPDATE Client_Payment_TB SET Pay_Mode=@PM, Cheque_DD_No=@CDN, Bank=@BK, Cheque_Date=@CDAT, Current_Date=@NOW, Discount_Amount=@DA, Paid=@PD, Remaining=@RM WHERE Bill_ID=@ID";
using (SqlCommand cmd = new SqlCommand(sql, con))
   {
   cmd.AddWithValue("@PM", Pay_Modes);
   cmd.AddWithValue("@CDN", txt_Chaque_No.Text);
   cmd.AddWithValue("@BK", txt_Bank.Text);
   cmd.AddWithValue("@CDAT", dateTimePicker_Chaque.Value);
   cmd.AddWithValue("@NOW", dateTimePicker_Current_date.Value);
   cmd.AddWithValue("@DA", txt_Discount.Text);
   cmd.AddWithValue("@PD", dpp);
   cmd.AddWithValue("@RM", txt_Remaining.Text);
   cmd.AddWithValue("@ID", txt_Bill_No.Text);
   ...
   }
 
Share this answer
 
Try specifying "#" instead of " ' " in the query.

For eg. " ChequeDate=#" + dateTimePicker_Chaque.Value.ToString("yyyy/MM/dd") + "#"
 
Share this answer
 
Comments
Herman<T>.Instance 22-Oct-13 7:36am    
The date values are indeed one of the point ACCESS is using different context than SQL
If I change your string to a formatted one you get the next:
SQL
String.Format("update Client_Payment_TB set Pay_Mode ='{0}', Cheque_DD_No ='{1}',Bank ='{2}', Cheque_Date ='{3}', Current_Date='{4}', Discount_Amount ='{5}'
, Paid ='{6}, Remaining='{7}' where Bill_ID='{8}'",Pay_Modes, txt_Cheque_No.Text, txt_Bank.Text, dateTimePicker_Chaque.Value, dateTimePicker_Current_date.Value,
txt_Discount.Text, dpp, txt_Remaining.Text, txt_Remaining.Text )


The question that arise:
- Why are money/decimal values set as string values? Are all conversions going well?
- Why you have your SQL statment not ended with a ; That ; is needed for Access! SQL doesn't bather the;
 
Share this answer
 
v2

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