Results 1 to 4 of 4

Thread: delete row from datatable

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    42

    delete row from datatable

    I can add rows and it automatically updates, work fine.
    but when i try to delete a row, some can be delete some cant. but after all when I reload the list everything is unchanged..

    Code:
     Dim response = MsgBox("Are you sure?", 4 Or 32, "")
                If response = MsgBoxResult.Yes Then
                    rownum = SCD_allowedDataGrid.CurrentRowIndex
                    SCD.SCD_allowed.Rows(rownum).Delete()
                    Me.SCD_allowedDataGrid.Update()
                  
                End If
    then i try this: i got an error " Update requires a valid DeleteCommand when passed DataRow collection with deleted rows."
    ok...i think i need a deletecommand.
    DELETE FROM [SCD allowed]
    WHERE ???? <<< what do i put here if i want to delete a selected row?

    Code:
     Dim response = MsgBox("Are you sure?", 4 Or 32, "")
                If response = MsgBoxResult.Yes Then
                    rownum = SCD_allowedDataGrid.CurrentRowIndex
                    SCD.SCD_allowed.Rows(rownum).Delete()
                   Me.SCD_allowedTableAdapter.Update(SCD.SCD_allowed)
                  
                End If
    Last edited by husky_doggy; Mar 2nd, 2009 at 09:22 AM.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: delete row from datatable

    Hey,

    Have a look at this very useful post here:

    http://www.vbforums.com/showthread.php?t=469872

    It shows you exactly how to go about doing this.

    Hope this helps!!

    Gary

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2008
    Posts
    42

    Re: delete row from datatable

    Quote Originally Posted by gep13
    Hey,

    Have a look at this very useful post here:

    http://www.vbforums.com/showthread.php?t=469872

    It shows you exactly how to go about doing this.

    Hope this helps!!

    Gary
    but i mean to delete a row by currentselectedrow in a tableadapter?

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: delete row from datatable

    I am not sure what you mean.

    Have you created the DeleteCommand as per the post that I linked you to?

    Deleting a row from the disconnected version of the data does not persist it through to the database, that is why you are seeing it re-appear. The only way to ensure that the data is deleted in the database is to use the DeleteCommand, and how to do this is shown in the link.

    Gary

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