MagicCity33
Member
Hello all,
I'm trying to update data in an Access database but according to VB.NET I have a syntax error in my UPDATE SQL Statement. I have looked over this code over and over and again but I just don't see any problems with what I have. I can update one field at a time but I would like to do is update an entire row based on the data entered into the textboxes on the form. Has anyone run into this problem before? What can I do to resolve this problem.
Here is my code:
Public AppPath = System.Windows.Forms.Application.StartupPath
Public Active_DB As String = "C:\Test\Agenda00.mdb"
Public ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Active_db & " ;User Id=admin;Password=;"
Public DBconn As OleDbConnection = New OleDbConnection(ConnStr)
Public DS As DataSet
Public objfrmMain As frmMain
DS = New DataSet ' This isn't used until I get ready to look back into the database to make sure my ' changes where made.
Try
Dim UpdateCMD As OleDbCommand = New OleDbCommand
UpdateCMD.CommandText = "UPDATE Agenda SET " _
& "AGDate = #" & objfrmMain.txtgb2Date.Text& "#, " _
& "Topic = '" & objfrmMain.txtgb2Topic.Text & "', " _
& "Time = #" & objfrmMain.txtgb2Time.Text & "#, " _
& "Additional = '" & objfrmMain.txtgb2Comment.Text & "'" _
& " WHERE ID = #" & objfrmMain.txtgb2old.Text & "#"
UpdateCMD.Connection = DBconn
UpdateCMD.ExecuteNonQuery()
DBconn.Close()
MsgBox("Update Completed!")
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Function
End Try
Thanks
I'm trying to update data in an Access database but according to VB.NET I have a syntax error in my UPDATE SQL Statement. I have looked over this code over and over and again but I just don't see any problems with what I have. I can update one field at a time but I would like to do is update an entire row based on the data entered into the textboxes on the form. Has anyone run into this problem before? What can I do to resolve this problem.
Here is my code:
Public AppPath = System.Windows.Forms.Application.StartupPath
Public Active_DB As String = "C:\Test\Agenda00.mdb"
Public ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Active_db & " ;User Id=admin;Password=;"
Public DBconn As OleDbConnection = New OleDbConnection(ConnStr)
Public DS As DataSet
Public objfrmMain As frmMain
DS = New DataSet ' This isn't used until I get ready to look back into the database to make sure my ' changes where made.
Try
Dim UpdateCMD As OleDbCommand = New OleDbCommand
UpdateCMD.CommandText = "UPDATE Agenda SET " _
& "AGDate = #" & objfrmMain.txtgb2Date.Text& "#, " _
& "Topic = '" & objfrmMain.txtgb2Topic.Text & "', " _
& "Time = #" & objfrmMain.txtgb2Time.Text & "#, " _
& "Additional = '" & objfrmMain.txtgb2Comment.Text & "'" _
& " WHERE ID = #" & objfrmMain.txtgb2old.Text & "#"
UpdateCMD.Connection = DBconn
UpdateCMD.ExecuteNonQuery()
DBconn.Close()
MsgBox("Update Completed!")
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Function
End Try
Thanks