0

when I use this

con.Open();
OleDbCommand conup = new OleDbCommand(@"UPDATE  [user1],
SET   name = '" + textBox1.Text + "' , password ='" + textBox2.Text + "', <br>remember ='" + remember + "' WHERE (name='" + textBox1.Text + "')", con);
conup.ExecuteNonQuery();
con.Close();

it shows me an exception

System.Data.OleDb.OleDbException was unhandled,
  HResult=-2147217900
  Message=Syntax error 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.ExecuteNonQuery()
       at Sober_TAILORING.login.button1_Click(Object sender, EventArgs e) in E:\Desktop\vs project\Sober TAILORING\Sober TAILORING\login.cs:line 86
       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(IntPtr 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 Sober_TAILORING.Program.Main() in E:\Desktop\vs project\Sober TAILORING\Sober TAILORING\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
  • What is your question? – user1511417 Sep 03 '17 at 12:02
  • Your error message is exactly correct. The string you're constructing for the query is not a valid query. You've got an extra comma after the table name and a random `
    ` in there. Beyond that, you should not be using string concatenation to construct queries. Use [parameters](https://stackoverflow.com/questions/16568461/is-it-possible-to-pass-parameters-programmatically-in-a-microsoft-access-update).
    – Bacon Bits Sep 03 '17 at 13:05

1 Answers1

0

And password is reserved word in Access, and it makes no sense to update name, thus:

OleDbCommand conup = new OleDbCommand(@"UPDATE [user1] SET [password] = '" + textBox2.Text + "', remember = '" + remember + "' WHERE ([name] = '" + textBox1.Text + "')", con);
Gustav
  • 53,498
  • 7
  • 29
  • 55