VB.net 在DataGrid 中删除记录出错:不能通过已删除的行访问该行的信息
环境:VB.net;Access;WinForm在DataGrid中任意选中一行按Delete键删除后,点BtnSave按钮保存出错:不能通过已删除的行访问该行的信息,在如下代码中注明了出错位置,因为需要对表中第2列进行加密后再保存到数据库,所以用了For each语句,但是在增加,修改记录的时候没有错误出现,请帮忙看看问题如何解决,谢谢!!
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DG_Fill()
End Sub
Private Sub DG_Fill()
Dim CMD As New OleDb.OleDbCommand("select BNO ,NM1,NM2,GH from MYTB", MyConnection)
MyAdapter.SelectCommand = CMD
If MyConnection.State = ConnectionState.Closed Then
MyConnection.Open()
End If
NDataSet.Clear()
MyAdapter.Fill(NDataSet, "MYTB")
MYDG.DataSource = NDataSet
MYDG.DataMember = "MYTB"
MYDG.Refresh()
MyConnection.Close()
End Sub
Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
Dim nr As DataRow
For Each nr In NDataSet.Tables("MYTB").Rows
nr(1) = EncryptString(nr(1)) 'debug到此处出现错误:不能通过已删除的行访问该行的信息
Next
Dim cb As New OleDb.OleDbCommandBuilder(MyAdapter)
MyAdapter.Update(NDataSet, "MYTB")
DG_Fill()
End Sub --------------------编程问答-------------------- 哪位大哥有空帮忙看看啊,在线等! --------------------编程问答-------------------- 我也想知道,正在找這方面的資料~~~~~ --------------------编程问答-------------------- 不会,帮顶
补充:VB , 数据库(包含打印,安装,报表)