2014-03-06 45 views
0

这是我的删除按钮代码。当我点击删除按钮时,它会显示错误消息“已删除的行信息无法通过该行进行访问”。那么,可能的解决方案是什么?VB.NET - 无法通过该行访问已删除的行信息

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
    If (i < ds.Tables(0).Rows.Count - 1) Then 
     Dim r1 As DataRow 
     'r1 = ds.Tables(0).NewRow(i)(0) 
     'r1.Delete() 
     'Me.da.Update(ds.Tables(0)) 
     ds.Tables(0).Rows(i).Delete() 
     ds.Tables(0).GetChanges(DataRowState.Deleted) 
     'ds.Tables(0).AcceptChanges() 
     'ds.AcceptChanges() 
     'Me.da.Update(Me.ds.Tables(0).Rows(i)("cust_id")).ToString() 
     'Me.da.Update(Me.ds.Tables(0).Rows(i)("cust_id")) 
     Me.da.Update(Me.ds.Tables(0).Rows(i).Item(0)) 
     ' Me.da.Update(Me.ds.Tables(0)) 
     ' ds.Tables(0).AcceptChanges() 

     i = i + 1 
     TextBox1.Text = ds.Tables(0).Rows(i)("cust_id").ToString() 
     TextBox2.Text = ds.Tables(0).Rows(i)("fname").ToString() 
     TextBox3.Text = ds.Tables(0).Rows(i)("sname").ToString() 
     TextBox4.Text = ds.Tables(0).Rows(i)("lname").ToString() 
     TextBox5.Text = ds.Tables(0).Rows(i)("address").ToString() 
     TextBox6.Text = ds.Tables(0).Rows(i)("city").ToString() 
     TextBox7.Text = ds.Tables(0).Rows(i)("state").ToString() 
     TextBox8.Text = ds.Tables(0).Rows(i)("contact1").ToString() 
     TextBox9.Text = ds.Tables(0).Rows(i)("contact2").ToString() 
     TextBox10.Text = ds.Tables(0).Rows(i)("email").ToString() 

    End If 
End Sub 
+0

首先,什么是'ds'和'da'?其次,在函数的开始处插入一个断点,然后遍历代码以找出发生错误的行。 –

+0

尝试在删除后重新分配ds。 – matzone

回答

0

你必须在网格或其他控件,当你删除它显示的数据,信息刷新在屏幕上,这是当控制抛出的信息不能被访问的错误。

在您删除表格中的一行之前,您需要确保将其从任何UI元素(如绑定源或网格)中删除。

相关问题