Home All Groups Group Topic Archive Search About
Author
29 Jun 2006 2:10 PM
beGentle-Learner
Hi guys

I want to e able to delete rows from a datagrid and the same rows must be
deleted from the datasource of the datagrid. I have a buon that removes a row
based on a field value that is listed in a list box. here is te code:
Dim tbl As New DataTable("DATAdemo")
         tbl = Me.DataSet1.Tables(0)
         Dim a As Integer

  For a = 0 To ListBox1.Items.Count
               tbl.Rows.RemoveAt([a])
               Me.OleDbDataAdapter1.Update(tbl)
               Me.Refresh()
               ListBox1.Items.Clear()
            Next

Can somebody modify my code to accomplish my mission?
Thanx

Author
29 Jun 2006 2:41 PM
Cor Ligthert [MVP]
BeGentle,

Your problem is that you removes the row, which means that it is removed
from the table. In the update there is no information anymore to remove it
from the database. For this case the delete would be used.

http://msdn2.microsoft.com/en-us/library/system.data.datarow.delete.aspx

I hope this helps,

Cor

Show quoteHide quote
"beGentle-Learner" <beGentleLear***@discussions.microsoft.com> schreef in
bericht news:5318DC97-93F7-46FE-805F-B1FCC3AC2167@microsoft.com...
> Hi guys
>
> I want to e able to delete rows from a datagrid and the same rows must be
> deleted from the datasource of the datagrid. I have a buon that removes a
> row
> based on a field value that is listed in a list box. here is te code:
> Dim tbl As New DataTable("DATAdemo")
>         tbl = Me.DataSet1.Tables(0)
>         Dim a As Integer
>
>  For a = 0 To ListBox1.Items.Count
>               tbl.Rows.RemoveAt([a])
>               Me.OleDbDataAdapter1.Update(tbl)
>               Me.Refresh()
>               ListBox1.Items.Clear()
>            Next
>
> Can somebody modify my code to accomplish my mission?
> Thanx