Trying to delete from datatable

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi - I have a datatable, held in a session variable - I want to delete
all items in a particular category, but my code doesn't seem to delete
them - although the delete method is run:

Function delCat(ByVal Cat as integer)

objDT = Session("Cart")
Dim i as Integer
Dim test as Integer

For i = objDT.Rows.Count-1 to 0 step -1
test = CType(objDT.Rows(i)("Category"), Integer)
If test = Cat then
objDT.Rows(i).Delete()
End If
Next
Session("Cart") = objDT

End Function

Can anyone please help show me where I'm going wrong?

Thanks, Mark
 
That marks the record for deletion when updating to a database. If you want
to physically remove it from the table, you have to call the Remove or
RemoveAt method.
 
Hi - thanks, but I can't see a:

objDT.Rows(i).Remove in intellisense (VS.Net 2003)

Can you advise?

Thanks, Mark
 
Back
Top