ZeroEffect Posted August 4, 2008 Posted August 4, 2008 I am trying to add a record to my access database for the application I am building. I can connect and display data from the DB but when use my code to add a row I get this error. "Syntax error in INSERT INTO statement." My ID row is auto incrementing this might be the problem. The code I using is posted below. Thanks for your help. ZeroEffect Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim cb As New OleDb.OleDbCommandBuilder(daEvents) Dim dsNewRow As DataRow dsNewRow = dsEvents.Tables("events").NewRow() dsNewRow.Item("ID") = vbNull 'This is Auto incrementing in Access, Possible issue here dsNewRow.Item("EventName") = tbEventName.Text dsNewRow.Item("Command") = tbCommand.Text dsNewRow.Item("Time") = dtpTime.Text dsNewRow.Item("Days") = strSu & strM & strT & strW & strR & strF & strSa dsEvents.Tables("events").Rows.Add(dsNewRow) daEvents.Update(dsEvents, "events") MsgBox("New Record added to the Database") End Sub Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
pendragon Posted August 4, 2008 Posted August 4, 2008 I always set the Auto Inc. field to -1 when adding a record, not sure if this will fix your problem but worth a try Quote
ZeroEffect Posted August 4, 2008 Author Posted August 4, 2008 (edited) I tried this and I still get the same result. but with a little more research I found that my column labeled "Time" is a labeld with a reserved word. I changed it from "Time" to "RunTime" and everything worked. Here is a link to reserved works. http://www.xlinesoft.com/asprunnerpro/articles/sql_access_odbc_reserved_keywords.htm Thanks for your help. I am now working on getting the ID column to update in my DataGridView. It looks like all I have to do is reload the Data from the file. And Now I have another issue. When I delete a row I get this error, "Deleted row information cannot be accessed through the row." This only happens when the row being deleted is NOT the last row. Any thoughts on this? Here is my Code for deleteing and where the error is happening. Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim cb As New OleDb.OleDbCommandBuilder(daEvents) dsEvents.Tables("events").Rows(DataGridView.CurrentRow.Index).Delete() dsEvents.AcceptChanges() daEvents.Update(dsEvents, "events") 'DataGridView.DataSource = dsEvents.Tables("events") End Sub Here is where the debug stops Private Sub DataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView.SelectionChanged If blnFormClosing = False Then resetCB() tbEventName.Text = dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("EventName") tbCommand.Text = dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("Command") dtpTime.Text = dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("RunTime") Days(dsEvents.Tables("Events").Rows(DataGridView.CurrentRow.Index).Item("Days")) End If End Sub Thanks ZeroEffect Edited August 4, 2008 by ZeroEffect Quote If you can't find it, Build It. There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.