The DataAdapter.SelectCommand property needs to be initialized
10:45 23 Jan 2013

I want to save the modifications I made to a DataSet into the DataBase, but I got this error:

The DataAdapter.SelectCommand property needs to be initialized

This is the code I wrote:

dr = dt.NewRow

dr(0) = t1.Text
dr(1) = t2.Text
dr(2) = t3.Text
dr(3) = d1.Value

dt.Rows.Add(dr)

da.InsertCommand = cb.GetInsertCommand()
da.Update(ds, "stagiaire")
MsgBox("ajout effectu!")

dr is a DataRow / dt is a DataTable / da is a SqlDataAdapter / cb is a SqlCommandBuilder / ds is a DataSet

But when I changed this line : da.InsertCommand = cb.GetInsertCommand() with : cb = New SqlCommandBuilder(da) it worked.

So why the first code I used it didn't worked !

ado.net