Deleting Row from database from dataset

dsk96m

Well-known member
Joined
Jan 11, 2013
Messages
173
Programming Experience
1-3
I am trying to delete a row/record in a database that i have as a dataset in my program. The following is my code:

VB.NET:
        Dim flightid As Integer = DirectCast(DirectCast(FlightplanBindingSource.Current, System.Data.DataRowView).Row, Flight_Test_App.FlightTestAppDataSet.flightplanRow).id
        Dim chargeid As Integer = Me.ListBox1.SelectedValue
        Dim foundrows() As Data.DataRow
        foundrows = FlightTestAppDataSet.flightcharge.Select("flight_plan_id=" & flightid & " and charge_number_id=" & chargeid)

        For Each dr As DataRow In foundrows
            test = dr.Table.Rows.IndexOf((dr))
            FlightTestAppDataSet.flightcharge.Rows(test).Delete()
        Next

        Me.FlightchargeBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.FlightTestAppDataSet)

I believe it is deleting it from the dataset, but not from my database. It is an sql database. I have tried numerous things, but cant figure this out. Any suggestions. What am i missing?
 
Firstly, if you already have the row, what's the point of getting that row's index and then using that index to get the row again to delete it? Why not just delete the row in the first place and not worry about the index?

As for the issue, how do you know that it's not deleting it from your database? What value does UpdateAll return? If that's not zero then changes are being saved.
 
I changed a few things and am now getting update requires a valid deletecommand when passed datarow collection with deleted rows
 
No, there was no primary key and that was it. It is an intersecting table with no primary key. I added a new column made it primary and it seems to be working now. Thank you for your help.
 
Back
Top