Deleting a row in a datatable
-
How can I delete a row from a datatable based on a condition. Here is what I'm trying to do: Dim row As DataRow For Each row In Table1.Rows If (row("Name") = "Adam") Then Table1.Rows.Remove(row) End If 'MsgBox(row("Name")) Next Thanks, Martin
-
How can I delete a row from a datatable based on a condition. Here is what I'm trying to do: Dim row As DataRow For Each row In Table1.Rows If (row("Name") = "Adam") Then Table1.Rows.Remove(row) End If 'MsgBox(row("Name")) Next Thanks, Martin
put this in a click command dont forget to put in your binding manager, data adapter and dataset dimdgrdelete as dialogresult try dgrdelete = messagebox.show("delete this record?", _ "Confirm Delete",Messageboxbuttons.YesNo) if dgrdelete = dialogresult.yes then with bmanager 'bindingmanager .removeat(.postion) end with daAdapter.update(dsDataset) dsDataset.acceptchanges end if catch err as exception messagebox.show(err.message) end try James Kennelly
-
put this in a click command dont forget to put in your binding manager, data adapter and dataset dimdgrdelete as dialogresult try dgrdelete = messagebox.show("delete this record?", _ "Confirm Delete",Messageboxbuttons.YesNo) if dgrdelete = dialogresult.yes then with bmanager 'bindingmanager .removeat(.postion) end with daAdapter.update(dsDataset) dsDataset.acceptchanges end if catch err as exception messagebox.show(err.message) end try James Kennelly
oopps dim dgrdeleteas dialogresult James Kennelly
-
put this in a click command dont forget to put in your binding manager, data adapter and dataset dimdgrdelete as dialogresult try dgrdelete = messagebox.show("delete this record?", _ "Confirm Delete",Messageboxbuttons.YesNo) if dgrdelete = dialogresult.yes then with bmanager 'bindingmanager .removeat(.postion) end with daAdapter.update(dsDataset) dsDataset.acceptchanges end if catch err as exception messagebox.show(err.message) end try James Kennelly
I wasn't able to replicate your example, I never worked with the binding manager. Below is what I did. Is there a more efficint way? Dim row As DataRow Dim i As Int16 = 0 Dim ar As ArrayList = New ArrayList() For Each row In Table1.Rows If (row("Name") = "Adam") Then ar.Add(i) 'add the index of the row to be deleted End If i = i + 1 Next Dim index As Int16 For index = 0 To ar.Count - 1 Table1.Rows.RemoveAt(ar.Item(index)) Next datagrid1.SetDataBinding(Table1, Nothing) datagrid1.RetrieveStructure()
-
I wasn't able to replicate your example, I never worked with the binding manager. Below is what I did. Is there a more efficint way? Dim row As DataRow Dim i As Int16 = 0 Dim ar As ArrayList = New ArrayList() For Each row In Table1.Rows If (row("Name") = "Adam") Then ar.Add(i) 'add the index of the row to be deleted End If i = i + 1 Next Dim index As Int16 For index = 0 To ar.Count - 1 Table1.Rows.RemoveAt(ar.Item(index)) Next datagrid1.SetDataBinding(Table1, Nothing) datagrid1.RetrieveStructure()
Dim rows() as DataRow rows = Table1.Select(" Name = 'Adam' ") If rows.Length > 0 Then Table1.Rows.Remove(rows(0)) End if
Free your mind... -
Dim rows() as DataRow rows = Table1.Select(" Name = 'Adam' ") If rows.Length > 0 Then Table1.Rows.Remove(rows(0)) End if
Free your mind...This is what I needed. Thanks so much, Martin
-
This is what I needed. Thanks so much, Martin
How about if I want to remove ALL rows that dont' meet that criteria Table1.Select(" Name = 'Adam' ") Dim rows() as DataRow rows = Table1.Select(" Name = 'Adam' ") If rows.Length > 0 Then Table1.Rows.Remove(rows(0)) End if Thanks, Martin