how to use InsertCmd with data Adapter?

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Hello,

I have a data grid (grd1) on a form (vb.net) which
displays data correctly from an Access mdb table. I
populate the grid control with a typed dataset (ds1) which
I fill from a data adapter (da1), connection conn1.

Now I want to insert a record into the Access table and
reflect the new record on the grid. Here is my code which
does not work.

Private Sub btn1_click(...)
Dim cmd As New OleDBCommand("Insert Into tbl1(fld1) Values
('test')")
da1.InsertCommand = cmd
da1.Update(ds1)
End Sub

I respectfully request if someone could explain to me how
to do this correctly.

Thanks,
Rich
 
I think I have something here that sort of works.

Private Sub btn1(...)
Dim cb As New OleDbCommandBuilder(da1)
Dim dRow As DataRow = ds1.Tables(0).NewRow
dRow("fld1") = "test"
ds1.Tables(0).Rows.Add(dRow)
da1.Update(ds1)
End Sub

Any suggestions for improvements are welcome.

Rich
 
Rather than using commanbuilder, try creating adapters at design time, for
example by drag&drop tables from server explorer.
 
Back
Top