F
fiaolle
Hi
I'm new to ADO in Visual Basic.Net and have problems with updating the
DataSet. 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 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.
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
Me.OleDbDAFilmKat.DeleteCommand.Parameters.Add(New
System.Data.OleDb.OleDbParameter("@Original_Nr",
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
Please help!!!!!!!!!!!!!!!!!!!
I don't know what's wrong
Fia
I'm new to ADO in Visual Basic.Net and have problems with updating the
DataSet. 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 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.
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
Me.OleDbDAFilmKat.DeleteCommand.Parameters.Add(New
System.Data.OleDb.OleDbParameter("@Original_Nr",
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
Please help!!!!!!!!!!!!!!!!!!!
I don't know what's wrong
Fia