unvalid updatecommand

Wirloff

Member
Joined
Mar 2, 2005
Messages
19
Location
Belgium
Programming Experience
1-3
Hi,
I have filled da dataset (ds7) from a database with a dataAdapter. Each row presents a phone call (with "date", "time", "duration",..."

I have (just for practice) tried to manually change the date from the first record:
ds7.Tables("Call").Rows(0)("date") = "3/03/2003" (it was 12/12/2005)

When I check the dataset with:
MsgBox(ds7.Tables("Call").Rows(0)("date").ToString())

He shows me the new date, so I sure that I managed to change it inside the dataset

Then I write:
dataAdapterName.update(ds7, "call")

to write it back into database

but at runtime I get:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

I do not manage to solve this. Does it mean that i only should use commands like "UPDATE ... FROM...." and not just change te value???? :confused: Anybody has an idea?
 

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
Add, Update, and Delete

Add, Update, and Delete commands can get sticky really fast. The dataform wizard does a good job creating these commands for you. If you create a form with the dataform wizard and display the table in a grid, the wizard will generate code for Add, Update, and Delete.
It will create code on button events for triggering the events.
I started by letting the wizard generate the code and dataadapters/datasets for me then tweeking the code the way I like it.
I delete OLEDBAdapter and replace with SQLDataAdapter for instance. The code for the save button remains the same, I just have to change the DataSet, DataAdapter, and Connection Names.

here is an example of the wizard genertaed UpdateDataSet code:

Public Sub UpdateDataSet()
Dim DataSetChanges1 As GageReportTest.dsGage = New GageReportTest.dsGage
Me.BindingContext(DsGage1, "Gage").EndCurrentEdit()
DataSetChanges1 = CType(DsGage1.GetChanges, GageReportTest.dsGage)
If (Not (DataSetChanges1) Is Nothing) Then
Try
Me.UpdateDataSource(DataSetChanges1)
'DsGage1.Merge(DataSetChanges1)
DsGage1.AcceptChanges()
Catch eUpdate As System.Exception
Throw eUpdate
End Try
End If
End Sub

Public Sub UpdateDataSource(ByVal ChangedRows As GageReportTest.dsGage)
Try
If (Not (ChangedRows) Is Nothing) Then
Me.SqlConnection1.Open()
SqlDataAdapter1.Update(ChangedRows)
End If
Catch updateException As System.Exception
Throw updateException
Finally
Me.SqlConnection1.Close()
End Try
End Sub

Try it, it really works...
 

Wirloff

Member
Joined
Mar 2, 2005
Messages
19
Location
Belgium
Programming Experience
1-3
Thank you !!!

I've done it with the dataform wizard like you said, copied most of the code, and it works!! I have never would have found those commands by myself, they are really complex...Now my project can go on ;)
 
Top Bottom