ADO.NET - Problem with Insert-, Delete- and UpdateCommand

F

fiaolle

Hi

I'm new to ADO in Visual Basic.Net and have problems with updating the
DataSet after I have done ExecuteNonQuery.
I'm using the code below

Private Sub cmdDel_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdDel.Click
Me.OleDbConn.Open()
Me.OleDbDAFilmKat.DeleteCommand.Parameters(0).Value = Me.txtNr.Text
Me.OleDbDAFilmKat.DeleteCommand.ExecuteNonQuery()
Me.OleDbDAFilmKat.Update(DSFilm, "Film")
MaxRows = DSFilm.Tables("Film").Rows.Count
Me.OleDbConn.Close()
End sub

After this, when I'm using the DataSet DSFilm the DataSet isn't updated. But
when I restart the program the record is gone.
I have seen example where I should use Me.OleDbDAFilmKat.Fill(DSFilm,
"Film") instead, but it didn't help. I have also seen articles there I
should use this code
Dim oRow as DataRow
oRow = Me.DSFilm.Tables("Film").Rows(0)
oRow.Delete()
Then after that, use the DeleteCommand for the DataAdapter.
Do I have to do this above to delete a row in the Dataset, then use the
DataAdapter's DeleteCommand to delete a row in the Database. Isn't there
another way.
I have the same problem with InsertCommand and UpdateCommand.

Please Help !!!
Fia
 
G

Guest

Fia,

You need to use the data adapter's Update command to handle all changes
(inserts, updates, deletes) to the database.

Kerry Moorman
 
F

fiaolle

Hi
Thank's for your answer but I think I am using the DataAdapter's Update. In
my code the DataAdapter is OleDbDAFilmKat. I'm not sure what you mean.

Fia
 
G

Guest

Fia,

I meant don't call Me.OleDbDAFilmKat.DeleteCommand.ExecuteNonQuery().

Just call the data adapter's Update method. The data adapter decides to call
your Insert, Update or DeleteCommand based on the state of a particular row.

Kerry Moorman
 

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