943,640 Members | Top Members by Rank

Ad:
Aug 27th, 2009
0

Error when update database with vb.net

Expand Post »
Hi expert,
I'm facing a problem when i try to update the database, below is my code:
Dim conn As New OleDb.OleDbConnection
Dim strSQL As OleDb.OleDbCommand
Dim ra As Integer
Dim num

conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=C:\employee.mdb"
conn.Open()

strSQL = New OleDb.OleDbCommand("Update [emp] Set e_name = '" & txtName.Text & "', city = '" & txtCity.Text & "', phone_no = '" & txtPhone.Text & "', dob = '" & txtDob.Text & "', Position = '" & txtPosition.Text & "' where e_no = 2", conn)
ra = strSQL.ExecuteNonQuery()

MessageBox.Show("Records affected" & ra)
conn.Close()
conn.Dispose()

the error message was:
System.Data.OleDb.OleDbException was unhandled
ErrorCode=-2147217900
Message="Syntax error in UPDATE statement."
Source="Microsoft Office Access Database Engine"
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 TestingDatabase.Checking.cmdUpdate_Click(Object sender, EventArgs e) in C:\Documents and Settings\Chong\My Documents\Visual Studio 2008\Projects\TestingDatabase\TestingDatabase\Checking.vb:line 94 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.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at TestingDatabase.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 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:

can anyone show me where is the error?Please help, its urgent
Thanks for the help

Regards
Mike
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Steammike is offline Offline
5 posts
since Aug 2009
Aug 27th, 2009
0

Re: Error when update database with vb.net

The problem was that ‘Position’ which is reserved by the ms access, so just change the table row name then the problem was fixed ^&^
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Steammike is offline Offline
5 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS Access and FileMaker Pro Forum Timeline: How to manage .edb files?
Next Thread in MS Access and FileMaker Pro Forum Timeline: Fill checkbox automatically





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC