HiI'm new to ADO in Visual Basic.Net and have problems with updating theDataSet. I'm using the code below, but after I have used the DataAdapter's Update metod nothing happens to the Dataset OR the database (the record is not deleted). Before I used the ExecuteNonQuery, then the record was gone in the database but the record was still in the DataSet. I were told not to use the ExecuteNonQuery, so I commented it.I have seen example where I should use
instead, but it didn't help. I have also seen articles there Ishould use this code
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 theDataAdapter's DeleteCommand to delete a row in the Database. Isn't there another way.
Please help I don't know what's wrong
Fia
VB.NET:
Me.OleDbDAFilmKat.Fill(DSFilm,"Film")
instead, but it didn't help. I have also seen articles there Ishould use this code
VB.NET:
Dim oRow as DataRowoRow = 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 theDataAdapter's DeleteCommand to delete a row in the Database. Isn't there another way.
VB.NET:
Dim OleDbDAFilmKat As OleDb.OleDbDataAdapter
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim comText As New OleDb.OleDbCommand
Dim SQL As String = "SELECT Film.Nr, Film.Titel, Film.KategoriID FROM Film ORDER BY Film.Nr"
OleDbDAFilmKat = New OleDb.OleDbDataAdapter(SQL, OleDbConn)
comText.Connection = OleDbConn
comText.CommandText = "DELETE FROM Film WHERE (Nr = ?)"
Me.OleDbDAFilmKat.DeleteCommand = comText
Me.OleDbDAFilmKat.DeleteCommand.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Original_Nr",
Me.OleDbDAFilmKat.DeleteCommand.Parameters.Add(New System.Data.OleDb.OleDbType.Integer, 4))
OleDbDAFilmKat.Fill(DSFilm, "Film")
end sub
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 = CInt(Me.txtNr.Text)
'Me.OleDbDAFilmKat.DeleteCommand.ExecuteNonQuery()
Me.OleDbDAFilmKat.Update(DSFilm, "Film")
DSFilm.AcceptChanges()
MaxRows = DSFilm.Tables("Film").Rows.Count
Me.OleDbConn.Close()
End Sub
Fia