Deleting from a dataset

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
Hi there,

I have a problem deleting records froma dataset. It works for some but not for all.

Could you help determine what the problem is please:

VB.NET:
    Public Sub DeleteRecord(ByVal formObjects As List(Of Control), ByVal table As String, ByVal row As Integer, ByVal lastRow As Integer)

        dataSet.Tables(table).Rows.RemoveAt(row)
        lastRow -= 1

        If dataSet.Tables(table).Rows.Count > 0 Then

            If (row - 1) > 0 Or (row - 1) = 0 Then

                currentRow = (row - 1)
                Call FillData(formObjects, table, currentRow)

            ElseIf row < lastRow Or row = lastRow Or row = 0 Then

                currentRow = row
                Call FillData(formObjects, table, currentRow)

            End If

        Else

            Call AddNewRecord(formObjects)
            addNew = True

        End If

    End Sub

What it is supposed to do is delete the record from the dataset and either move back one record and if it can't move forward one. If there arent any more records call addnewrecord.

I do have 3 different screens for entering data into three different tables, but whenever i move screen the currentRow is always set to 0 and FillData is run with the current row as 0.

Thanks.

EDIT:

I think it only doesn't work once i have deleted one record.
 
Last edited:
My question is, would it be more efficient to do it my way, which is by constructing the sql statement via concatenation and then running it (see above).
Its most efficient to do it in the way advocated by the DW2 link in my signature; the dataset designer will create for you a datatable, and paired table adapter with pre-formed design time queries that are parameterized and secure

Never, ever do SQL with string concatenation, its the biggest security hole you can blow in a database app, and youll spend hours messing about wondering why it all comes tumbling down when a user tries to insert a name like O'Brien. String concatenation was the 80s - database access has moved on some 20 years since, to queries tha tthe database can cache in compiled form without the need to analyze and plan every time they are submitted (parse-to-execute ratio)

Because surely if it's selecting the whole database again, then just running my sql statement would be more efficient?
Yeah, but you dont select whole databases, you select a few records, in a parameterized query, show them, update them, augment them etc and send them back.

Really, I faithfully promise you, the DW2 link explains all this in painstaking 1-step at a time detail. Try it.. you'll like it, and when youre done, you think "Wow, Nice job microsoft"
 
I have been through DW2 over and over, but I still can't figure this out for my solution without having to rewrite the whole thing using the GUI options.
 
Back
Top