3
Answers

error in inserting values in access

Ankur gupta

Ankur gupta

14y
2.6k
1
i am facing this error............
" Update requires a valid InsertCommand when passed DataRow collection with new rows"

when i am running this code
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Dim cb11 As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(da_purchase_master)
        If rdpur.Checked = True Then
            da_purchase_master = New OleDb.OleDbDataAdapter("select * from purchase_master ", con)
            ds_purchase_master = New DataSet
            da_purchase_master.Fill(ds_purchase_master, "dpm")

            Dim dspurrow As DataRow
            dspurrow = ds_purchase_master.Tables("dpm").NewRow
            dspurrow.Item("purchase_id") = 345
            dspurrow.Item("purchase_date") = dtpdate.Value
            dspurrow.Item("purchase_mode") = "cash"
            dspurrow.Item("purchase_cost") = 444
            Dim str = cmbname.Text
            dspurrow.Item("vendor_id") = Val(str.Split("-")(0))
            dspurrow.Item("from") = "vendor"
            dspurrow.Item("advance") = 5677
            dspurrow.Item("balance_amnt") = 785

            ds_purchase_master.Tables("dpm").Rows.Add(dspurrow)
            da_purchase_master.Update(ds_purchase_master, "dpm")


            MsgBox("detail saved", MsgBoxStyle.Information, "PURCHASE DETAILS")
           
        End If
endsub

connection with acess is established in module :

 Public Sub connection_start()
        Dim cstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=temp.accdb"
        con = New OleDb.OleDbConnection
        con.ConnectionString = cstring
        con.Open()
    End Sub

please help me with this error
Answers (3)