Results 1 to 5 of 5

Thread: [RESOLVED] DATAROW Looping / Deleting

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    [RESOLVED] DATAROW Looping / Deleting

    Alright, I have this piece of code:

    vb Code:
    1. Assignments_SQLSelect()
    2.             Adapter.DeleteCommand = New OleDbCommand("DELETE FROM Assignments WHERE CIndex = @CIndex")
    3.             Adapter.DeleteCommand.Connection = Connection
    4.             Connection.Open()
    5.             With Adapter.DeleteCommand
    6.                 .Parameters.Add("@CIndex", OleDbType.Integer, 5, "CIndex")
    7.             End With
    8.             For Each DRow As DataRow In DS.Tables(0).Rows
    9.                 If DRow.Item("Student").ToString.Contains(.lstNames.Items.Item(.RIndex).Text) Then
    10.                     DRow = DS.Tables(0).Rows(.RIndex)
    11.                     DRow.Delete()
    12.                 End If
    13.             Next
    14.             Adapter.Update(DS)
    15.             DS.AcceptChanges()
    16.             Connection.Close()

    So what its suppose to do is Loop Through each Row in the Database and then IF the DRow Contains the .RIndex.Text Item then it will Delete (This is Fine, I did a Debug to see if it was finding the items & doing the IF Statment (and it Did)

    Problem: Its only deleting the First Row that Contains that Item, not the Rest. So.. how do I fix this? I tried putting Adapter.Update and DS.ACcept in the LOOP statement but came up with a ERROR.
    Last edited by Wesley008; Nov 10th, 2008 at 04:36 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width