By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Dataset insert into access database insert into Syntax error

P: 6
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. ElseIf NEWMODE = True Then 
  3.  
  4.             Dim oAdapter As OleDb.OleDbDataAdapter 
  5.             Dim cb As OleDb.OleDbCommandBuilder 
  6.             Dim dr As DataRow 
  7.             Dim ds As DataSet 
  8.             Dim strSQL As String = "SELECT * FROM [Private Criminal Complaints 2]" 
  9.  
  10.             ds = New DataSet() 
  11.             oAdapter = New OleDb.OleDbDataAdapter(strSQL, Con) 
  12.             oAdapter.Fill(ds) 'Execute the Query and grab results 
  13.  
  14.             Try 
  15.                 dr = ds.Tables(0).NewRow() 
  16.  
  17.                 dr.BeginEdit() 
  18.  
  19.                 dr.Item("CompLastName") = txtCLname.Text 
  20.                 dr.Item("CompFirstName") = txtCFname.Text 
  21.                 dr.Item("DefLastName") = txtDLname.Text 
  22.                 dr.Item("DefFirstName") = txtDFname.Text 
  23.                 dr.Item("NameADA") = txtADA.Text 
  24.                 dr.Item("Detective") = txtDet.Text 
  25.                 dr.Item("Disposition") = txtDisposition.Text 
  26.                 dr.Item("ReasonFiled") = txtreason.Text 
  27.                 dr.Item("DateFiled") = txtDate.Text 
  28.  
  29.  
  30.                 dr.EndEdit() 
  31.  
  32.                 ds.Tables(0).Rows.Add(dr) 
  33.                 cb = New OleDb.OleDbCommandBuilder(oAdapter) 
  34.                 oAdapter.InsertCommand = cb.GetInsertCommand() 
  35.                 oAdapter.Update(ds) 
  36.                 ds.AcceptChanges() 
  37.  
  38.                 MessageBox.Show("Insert Successful") 
  39.                 NEWMODE = False 'Add success, end NEWMODE 
  40.                 ClearTextBoxes() 'Add Success, clean up textboxes 
  41.             Catch ex As Exception 
  42.                 MessageBox.Show(ex.Message) 
  43.  
  44.             Finally 
  45.                 Con.Close() 
  46.             End Try 
  47.  
  48.         Else 'Its not Editmode or Newmode 
  49.             'Do nothing 
  50.         End If 
  51.  
  52.         RefreshLV() 'Regardless of what happens, might as well refresh the data in the Listview 
  53.     End Sub 
  54.  
Dec 6 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.