Click here to Skip to main content
15,900,589 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi i have "(Syntax error in UPDATE statement.)" when I updating the record in access database by c# source code:
C#
OleDbConnection connect = new OleDbConnection(@"path.mdb");
           OleDbCommand cmd = new OleDbCommand();

               cmd.CommandType = CommandType.Text;
               cmd.CommandText = "UPDATE Table2 set check=2 whene key=asd ";
               cmd.Connection = connect;
               connect.Open();
               cmd.ExecuteNonQuery();
               connect.Close();

thank you for solution my problems
Posted
Updated 13-Aug-12 23:00pm
v2

Your keyword is incorrect .

It should be where instead of whene.
Also When you are using string in where clause, it should be written in single quotes.
like 'asd' instead of asd


C#
cmd.CommandText = "UPDATE Table2 set check='2' where key='asd'";
 
Share this answer
 
v4
Comments
AshishChaudha 14-Aug-12 5:09am    
my 5!
jihad anwar 14-Aug-12 5:17am    
thanks

i checked it but i did not get correct answer.
please help me again
Santhosh Kumar Jayaraman 14-Aug-12 5:22am    
post ur code again
Rahul Rajat Singh 14-Aug-12 5:19am    
+5.
jihad anwar 14-Aug-12 5:28am    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace qamus
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
OleDbConnection connect = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=E:\qamus.mdb");

private void button1_Click(object sender, EventArgs e)
{

OleDbCommand cmd = new OleDbCommand();

cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE Table2 set check='2' where key='"+richTextBox2.Text+"' ";
cmd.Connection = connect;
connect.Open();
cmd.ExecuteNonQuery();
connect.Close();


}

private void richTextBox2_TextChanged(object sender, EventArgs e)
{

}
}
}
Please check following line and update it.

Please define the datatype of field check and key.
C#
cmd.CommandText = "UPDATE Table2 set check='2' where key='asd' ";


Thanks
Ashish
 
Share this answer
 
v3
Comments
jihad anwar 14-Aug-12 5:11am    
thanks
but not solved
please help me as son as possible to answer me
because i need it so mach .
AshishChaudha 14-Aug-12 5:14am    
please see my updated solution
Edit to :
C#
cmd.CommandText = "UPDATE Table2 set check=2 where key='asd' ";


EDIT :
If you are using an Access database your connection string must be : http://www.connectionstrings.com/access/[^]
 
Share this answer
 
v2
Comments
jihad anwar 14-Aug-12 5:07am    
thanks
but not solved
jihad anwar 14-Aug-12 5:07am    
please help me
Mehdi Gholam 14-Aug-12 5:21am    
Check the update.
I had the same problem long back, i added textbaox1.text.tostring(); it works fine.

in your code also use richTextBox2.Text.tostring();
 
Share this answer
 
Comments
jihad anwar 14-Aug-12 5:53am    
thanks
but not solved please help me.
why are you giving check value in quotes.Try giving lik this in your code.

SQL
cmd.CommandText = "UPDATE Table2 set check=2 where  key='"+richTextBox2.Text+"' ";
 
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