Syntax error in UPDATE statement.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px
I have one code for updating the password, however the code is giving the error that "Syntax error in UPDATE statement.", before this I was getting error "<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px Syntax
error in Insert into statement" which was solved by " Noam B ", the link to that page is
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/47f0c3b2-ef52-482f-aea7-703a48656f00" target="_blank" title="Syntax error in Insert into statement
here . Now i am getting these error. I tried to solve it but no success, can you guys help me once again.
The code that I have written is:

<div style="color:black; background-color:white
<pre><span style="color:blue using System;
<span style="color:blue using System.Collections.Generic;
<span style="color:blue using System.ComponentModel;
<span style="color:blue using System.Data;
<span style="color:blue using System.Drawing;
<span style="color:blue using System.Text;
<span style="color:blue using System.Windows.Forms;
<span style="color:blue using System.Data.OleDb;

<span style="color:blue namespace Cyber_Application
{
<span style="color:blue public <span style="color:blue partial <span style="color:blue class ChangePassword : Form
{
<span style="color:blue string connectionString = <span style="color:#a31515 "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Cyber Application\param.accdb; Jet OLEDB:Database Password=123456";

<span style="color:blue public ChangePassword()
{
InitializeComponent();
}

<span style="color:blue private <span style="color:blue void changePassword()
{
OleDbConnection cn = <span style="color:blue new OleDbConnection(connectionString);
cn.Open();
<span style="color:blue string scmd1 = <span style="color:#a31515 "UPDATE EnterSoftware set Password = " + txtNewPassword.Text + <span style="color:#a31515 " where UserName = admin";
OleDbCommand cmd1 = <span style="color:blue new OleDbCommand(scmd1, cn);
OleDbDataReader sdr1 = cmd1.ExecuteReader();
cn.Close();
MessageBox.Show(<span style="color:#a31515 "Password has been changed successfully", <span style="color:#a31515 "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
<span style="color:blue this.Close();
}

<span style="color:blue private <span style="color:blue void btnOk_Click(<span style="color:blue object sender, EventArgs e)
{
OleDbConnection cn = <span style="color:blue new OleDbConnection(connectionString);
cn.Open();
<span style="color:blue string scmd = <span style="color:#a31515 "select Password from EnterSoftware";
OleDbCommand cmd = <span style="color:blue new OleDbCommand(scmd, cn);
OleDbDataReader sdr = cmd.ExecuteReader();

<span style="color:blue while (sdr.Read())
{
<span style="color:blue if (txtCurrentPassword.Text == sdr[<span style="color:#a31515 "Password"].ToString())
{
<span style="color:blue if (txtNewPassword.Text == <span style="color:#a31515 "" || txtConfirmPassword.Text == <span style="color:#a31515 "")
{
MessageBox.Show(<span style="color:#a31515 "Password cannot be blank", <span style="color:#a31515 "Change Password Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

<span style="color:blue if (txtNewPassword.Text == txtConfirmPassword.Text && txtNewPassword.Text != <span style="color:#a31515 "" || txtConfirmPassword.Text != <span style="color:#a31515 "")
{
changePassword();
}
<span style="color:blue else
{
MessageBox.Show(<span style="color:#a31515 "Password do not match", <span style="color:#a31515 "Change Password Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtCurrentPassword.Text = <span style="color:#a31515 "";
txtNewPassword.Text = <span style="color:#a31515 "";
txtConfirmPassword.Text = <span style="color:#a31515 "";
txtCurrentPassword.Focus();
}
}

<span style="color:blue else
{
MessageBox.Show(<span style="color:#a31515 "Invalid Current Password", <span style="color:#a31515 "Change Password Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtCurrentPassword.Text = <span style="color:#a31515 "";
txtNewPassword.Text = <span style="color:#a31515 "";
txtConfirmPassword.Text = <span style="color:#a31515 "";
txtCurrentPassword.Focus();
}
}
cn.Close();
}
}
}

[/code]

<br/>
The error code is as below:<br/>

<div style="color:black; background-color:white
<pre>System.Data.OleDb.OleDbException was unhandled
Message=Syntax error <span style="color:blue in UPDATE statement.
Source=Microsoft Office Access Database Engine
ErrorCode=-2147217900
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at Cyber_Application.ChangePassword.changePassword() <span style="color:blue in E:ClientsS V Cyber CafeCyber ApplicationCyber ApplicationChangePassword.cs:line 27
at Cyber_Application.ChangePassword.btnOk_Click(Object sender, EventArgs e) <span style="color:blue in E:Cyber ApplicationChangePassword.cs:line 52
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at Cyber_Application.MainForm.changePasswordToolStripMenuItem_Click(Object sender, EventArgs e) <span style="color:blue in E:ClientsS V Cyber CafeCyber ApplicationCyber ApplicationMainForm.cs:line 79
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Cyber_Application.Program.Main() <span style="color:blue in E:ClientsS V Cyber CafeCyber ApplicationCyber ApplicationProgram.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

[/code]

<br/>
<br/>

<br/>

View the full article
 
Back
Top