主题:在线等答复,实现"删除"功能时出错
我在实现主窗体中一项删除功能时,老是出现这样的错误:"未处理的"System.Runtime.InteropServices.COMException"类型的异常出现在系统.exe中
以下是我写的程序代码,望高手帮忙
Private Sub MenuItemAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemAdd.Click
Dim i As Integer
Dim Emp_id(MyRs.RecordCount) As Integer
Dim NewEmp_id As Integer
Dim flag As Boolean = False
NewEmp_id = MyRs.RecordCount
MyRs.MoveFirst()
For i = 0 To MyRs.RecordCount - 1
Emp_id(i) = Val(MyRs.Fields(0).Value.ToString)
MyRs.MoveNext()
Next
'将各记录的第一个字段(即“编号”字段)的值依次存储到数组中
For i = 0 To MyRs.RecordCount - 1
If NewEmp_id = Emp_id(i) Then flag = True
Next
Do While flag
NewEmp_id = 10000 * Rnd()
flag = False
For i = 0 To MyRs.RecordCount - 1
If NewEmp_id = Emp_id(i) Then flag = True
Next
Loop
'生成不重复的记录编号
MyRs.AddNew()
MyRs.Fields(0).Value = NewEmp_id
[color=FF0000]MyRs.Fields(1).Value = "Family_Name" + NewEmp_id.ToString[/color]
MyRs.Fields(2).Value = "Last_Name" + NewEmp_id.ToString
MyRs.Update()
'添加新的记录
Me.TreeView1.Nodes.Clear()
MyRs.MoveFirst()
For i = 0 To MyRs.RecordCount - 1
Me.TreeView1.Nodes.Add(MyRs.Fields(1).Value.ToString + MyRs.Fields(2).Value.ToString)
MyRs.MoveNext()
Next
'刷新TreeView
End Sub
//红色那条是调试时出错的地方
以下是我写的程序代码,望高手帮忙
Private Sub MenuItemAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemAdd.Click
Dim i As Integer
Dim Emp_id(MyRs.RecordCount) As Integer
Dim NewEmp_id As Integer
Dim flag As Boolean = False
NewEmp_id = MyRs.RecordCount
MyRs.MoveFirst()
For i = 0 To MyRs.RecordCount - 1
Emp_id(i) = Val(MyRs.Fields(0).Value.ToString)
MyRs.MoveNext()
Next
'将各记录的第一个字段(即“编号”字段)的值依次存储到数组中
For i = 0 To MyRs.RecordCount - 1
If NewEmp_id = Emp_id(i) Then flag = True
Next
Do While flag
NewEmp_id = 10000 * Rnd()
flag = False
For i = 0 To MyRs.RecordCount - 1
If NewEmp_id = Emp_id(i) Then flag = True
Next
Loop
'生成不重复的记录编号
MyRs.AddNew()
MyRs.Fields(0).Value = NewEmp_id
[color=FF0000]MyRs.Fields(1).Value = "Family_Name" + NewEmp_id.ToString[/color]
MyRs.Fields(2).Value = "Last_Name" + NewEmp_id.ToString
MyRs.Update()
'添加新的记录
Me.TreeView1.Nodes.Clear()
MyRs.MoveFirst()
For i = 0 To MyRs.RecordCount - 1
Me.TreeView1.Nodes.Add(MyRs.Fields(1).Value.ToString + MyRs.Fields(2).Value.ToString)
MyRs.MoveNext()
Next
'刷新TreeView
End Sub
//红色那条是调试时出错的地方