Error updating from dataset

ramyar

Member
Joined
Oct 16, 2002
Messages
5
Hi,

When I try to update the database table from the dataset table after inserting a new row in the datasets datatable I get the following error

------------------------------------------
An unhandled exception of type System.InvalidOperationException occurred in system.data.dll

Additional information: The DataAdapter.SelectCommand property needs to be initialized.
------------------------------------------

at the line

"adpProject.Update(dsProj, "Tasks")"

But I have initialised the dataadapters selectcommand property.



cnPMS.Open()

Create a SqlDataAdapter for the Project table.
Dim adpProject As SqlDataAdapter = New SqlDataAdapter()
A table mapping tells the adapter what to call the table.
adpProject.TableMappings.Add("Table", "Tasks")

Dim cmdProject As SqlCommand = _
New SqlCommand("SELECT * FROM Tasks", cnPMS)
cmdProject.CommandType = CommandType.Text

adpProject.SelectCommand = cmdProject
adpProject.Fill(ds)

BEGIN SEND CHANGES TO SQL SERVER
Dim objCommandBuilder As New SqlCommandBuilder(adpProject)
adpProject.Update(dsProj, "Tasks")
END SEND CHANGES TO SQL SERVER


Please Help. Thanks.
 
The dataset you fill is created as ds.
Your trying to update the db based on the dataset dsProj.
Has that dataset been mapped for the dataadapter? I dont see any evidence of that occuring.

ADO.net works differently than ADO. Check on the dataadapter as an example, it opens and closes the connection as neccessary. Delete the cnPMS.Open let the dataadapter.fill(dataset, "sourcetable"), and dataadapter.update(dataset, "sourcetable") do the opening and closing, its more efficient.

Jon
 
Back
Top