Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Posted (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 by ZeroEffect

If you can't find it, Build It.

 

There is no place Like 127.0.0.1 also don't forget 1 + 1 = 10

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...