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
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