Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

When I try to update the database table from the dataset table after inserting a new row in the dataset's 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 dataadapter's 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.

  • 1 year later...
  • *Experts*
Posted

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 don't 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, it's more efficient.

 

Jon

  • 5 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...