Difference between Delete method and RemoveRow method

C

CW

I am using a dataset1.xsd and its generated dataset11 object (via the use of
sqldataadapter wizard) to bind to a datagrid.

However, I have found a peculiar problem.

When a user hits the delete button on the datagrid and my code behind
handles the event, I originally chose the following code:

Dim dr As DataSet1.CMRC_CategoriesRow

dr =
Me.Dataset11.CMRC_Categories.FindByCategoryID(CInt(Me.dgProductCategories.It
ems(e.Item.ItemIndex).Cells(0).Text))

Me.Dataset11.CMRC_Categories.RemoveCMRC_CategoriesRow(dr)

me.sqlDataAdapter1.Update(Me.Dataset11)



However, the above code didn't work. For some reason, the row selected for
deletion never quite gets deleted.



Then I switched to this line code

Me.Dataset11.Tables("cmrc_categories").Rows.Item(e.Item.ItemIndex).Delete()

in place of the first 3 lines of code above.

While the second version is shorter (and most importantly works), why does
the 1st version not work? Conceptually, I prefer the 1st version because I
can avoid using collection indexing where bugs do not show up till run time.



Any ideas?



Thanks in advance

CW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top