Dataset insert into access database insert into Syntax error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ed Pisa
    New Member
    • Dec 2010
    • 6

    Dataset insert into access database insert into Syntax error

    Hello,

    I have been working with this problem now for several days. I can delete and Update my data but I can not get it to insert a new record. I receive the syntax error insert into. I am not using any reserved words and I have not been able to find my answer googling like crazy. Any help would be greatly appreciated. below is the code that seems to give me the problem.

    Code:
    ElseIf NEWMODE = True Then 
      
                Dim oAdapter As OleDb.OleDbDataAdapter 
                Dim cb As OleDb.OleDbCommandBuilder 
                Dim dr As DataRow 
                Dim ds As DataSet 
                Dim strSQL As String = "SELECT * FROM [Private Criminal Complaints 2]" 
      
                ds = New DataSet() 
                oAdapter = New OleDb.OleDbDataAdapter(strSQL, Con) 
                oAdapter.Fill(ds) 'Execute the Query and grab results 
      
                Try 
                    dr = ds.Tables(0).NewRow() 
      
                    dr.BeginEdit() 
      
                    dr.Item("CompLastName") = txtCLname.Text 
                    dr.Item("CompFirstName") = txtCFname.Text 
                    dr.Item("DefLastName") = txtDLname.Text 
                    dr.Item("DefFirstName") = txtDFname.Text 
                    dr.Item("NameADA") = txtADA.Text 
                    dr.Item("Detective") = txtDet.Text 
                    dr.Item("Disposition") = txtDisposition.Text 
                    dr.Item("ReasonFiled") = txtreason.Text 
                    dr.Item("DateFiled") = txtDate.Text 
      
      
                    dr.EndEdit() 
      
                    ds.Tables(0).Rows.Add(dr) 
                    cb = New OleDb.OleDbCommandBuilder(oAdapter) 
                    oAdapter.InsertCommand = cb.GetInsertCommand() 
                    oAdapter.Update(ds) 
                    ds.AcceptChanges() 
      
                    MessageBox.Show("Insert Successful") 
                    NEWMODE = False 'Add success, end NEWMODE 
                    ClearTextBoxes() 'Add Success, clean up textboxes 
                Catch ex As Exception 
                    MessageBox.Show(ex.Message) 
      
                Finally 
                    Con.Close() 
                End Try 
      
            Else 'Its not Editmode or Newmode 
                'Do nothing 
            End If 
      
            RefreshLV() 'Regardless of what happens, might as well refresh the data in the Listview 
        End Sub
Working...