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

Updating Access database from dataset with visual basic (2005)

P: 3
Hi,
I am new to this forum and have been troubled by this problem for the past few days. I would appreciate if someone would take a look and help me out.

I am using vb express 2005 edition... I have problem when updating MS Access database from dataset using vb(2005)
Expand|Select|Wrap|Line Numbers
  1. Dim sql As String = "SELECT * FROM SB_ADWarning"
  2. Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\SB_2000.mdb"
  3. Dim Con As New OleDbConnection(strConnString)
  4. Dim da As New OleDbDataAdapter(sql, Con)
  5. Dim ds As New DataSet()
  6. Dim dt As DataTable
  7. Dim dsNewRow As DataRow
  8. Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
  9. da.Fill(ds, "ADWarning")
  10. Con.Close()
  11. dt = ds.Tables("ADWarning")
  12. Try
  13. dsNewRow = dt.NewRow()
  14. dsNewRow("IssueDate") = Me.TextBox1.Text
  15. dsNewRow("IssueTime") = Me.TextBox2.Text
  16. dsNewRow("FcstOnsetTime") = Me.TextBox3.Text
  17. dsNewRow("FcstCldAmt") = Me.TextBox4.Text
  18. dt.Rows.Add(dsNewRow)
  19. Dim drModified As DataRow() = dt.Select(Nothing, Nothing, DataViewRowState.Added)
  20. Con.Open()
  21. ListBox1.DataSource = ds.Tables("ADWarning")
  22. ListBox1.DisplayMember = "IssueDate"
  23. da.UpdateCommand = cb.GetInsertCommand
  24. da.Update(drModified)
  25. MessageBox.Show("Database has been updated!", "Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
  26. Catch eInsertException As Exception
  27. MsgBox(eInsertException.Message & eInsertException.Source)
  28. Throw eInsertException
  29. Finally
  30. Con.Close()
  31. End Try
  32.  
I get an error prompt when debugging
System.Oledb.OledbException: {"Syntax error in INSERT INTO statement."}
error code: -2147217900
error source: Microsoft JET Database Engine
Mar 19 '07 #1
Share this Question
Share on Google+
1 Reply


MMcCarthy
Expert Mod 10K+
P: 14,534
VBA is very different to VB. My instinct says that you can't do it this way but I'm no expert. I'm going to ask one of the VB experts to take a look at it.

Mary
Mar 22 '07 #2

Post your reply

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