Datatable row deleting

J

Jacksm

When I delete a row using datatable.row.delete() it deletes the row
from the datatable instead of just marking it in the datatable so when
I go to to an adapter.update(datatable) i am getting primary key
violations. Any help would be appreciated above is my code for
deleting a row. It has been working but now it is not.

When I post back to the gridview the correct rows are deleted, but it
it deleting them from the datatable as well.

Protected Sub grvMain_RowDeleting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles
grvMain.RowDeleting
Dim dtCart As System.Data.DataTable
Dim c, i, j As Integer

dtCart = Session("Cart")


i = e.RowIndex + 1

For j = i To dtCart.Rows.Count - 1
Dim ae As Integer = dtCart.Rows(j).Item(0)
dtCart.Rows(j).Item(0) = ae - 1
Next

dtCart.Rows(e.RowIndex).Delete()

Session("Cart") = dtCart
grvMain.DataSource = dtCart
grvMain.DataBind()
 
C

Cor Ligthert [MVP]

Jacsm,

I don't understand this, if the row is removed from the table than there is
no update so there can as well be no primary key violation?

Can you tell us something more about the structure of your dataset?

Cor
 

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

Top