Updating Access database from dataset with visual basic (2005)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leaf0209
    New Member
    • Mar 2007
    • 3

    Updating Access database from dataset with visual basic (2005)

    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)
    Code:
    Dim sql As String = "SELECT * FROM SB_ADWarning"
    Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\SB_2000.mdb"
    Dim Con As New OleDbConnection(strConnString)
    Dim da As New OleDbDataAdapter(sql, Con)
    Dim ds As New DataSet()
    Dim dt As DataTable
    Dim dsNewRow As DataRow
    Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
    da.Fill(ds, "ADWarning")
    Con.Close()
    dt = ds.Tables("ADWarning")
    Try
    dsNewRow = dt.NewRow()
    dsNewRow("IssueDate") = Me.TextBox1.Text
    dsNewRow("IssueTime") = Me.TextBox2.Text
    dsNewRow("FcstOnsetTime") = Me.TextBox3.Text
    dsNewRow("FcstCldAmt") = Me.TextBox4.Text
    dt.Rows.Add(dsNewRow)
    Dim drModified As DataRow() = dt.Select(Nothing, Nothing, DataViewRowState.Added)
    Con.Open()
    ListBox1.DataSource = ds.Tables("ADWarning")
    ListBox1.DisplayMember = "IssueDate"
    da.UpdateCommand = cb.GetInsertCommand
    da.Update(drModified)
    MessageBox.Show("Database has been updated!", "Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
    Catch eInsertException As Exception
    MsgBox(eInsertException.Message & eInsertException.Source)
    Throw eInsertException
    Finally
    Con.Close()
    End Try
    I get an error prompt when debugging
    System.Oledb.Ol edbException: {"Syntax error in INSERT INTO statement."}
    error code: -2147217900
    error source: Microsoft JET Database Engine
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    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

    Comment

    Working...