how to use InsertCmd with data Adapter?

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
 
R

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
 
M

Miha Markic [MVP C#]

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top