[求助]关于修改表里多条记录的问题
'本窗体既作为"添加部门"又作为"修改部门"Public conn As ADODB.Connection
Public strSQL As String
Private Sub Command1_Click()
Dim str As New ADODB.Recordset
Set str = New ADODB.Recordset
'------------
If Me.Caption = "添加部门" Then
str.CursorLocation = adUseClient
str.Open "select * from department", conn, adOpenStatic, adLockReadOnly '取出表中的记录数,
'目的是取出它的最后
'一条记录的ID,方便添加新记录
strSQL = "insert into department values('" & "0" & str.RecordCount + 1 & "','" & Trim$(Text1.text) & "','')"
Set str = Nothing
'------------ 以上是添加部门(即添加根结点)
Else
' -----------
strSQL = "select id from department where main_menu='" & Trim$(FrmDepartmentSz.TreeView1.SelectedItem.text) & "'"
If str.State = adStateOpen Then str.Close
str.Open strSQL, conn, adOpenStatic, adLockReadOnly
' ----------取出要修改部门的所有ID
If str.RecordCount > 1 Then '如果一个部门有多条记录(多个根结点),则根据ID对多条记录修改
str.MoveFirst
For i = 1 To str.RecordCount
strSQL = "update department set main_menu='" & Trim$(Text1.text) & "' where id= '" & Trim$(str!id) & "'"
If str.State = adStateOpen Then str.Close
str.Open strSQL, conn, adOpenStatic, adLockReadOnly
’ str.MoveNext
Next i
Set str = Nothing
Resume DYtreechange
Else
’ 如果一个部门有一条记录(一个根结点)
strSQL = "update department set main_menu='" & Trim$(Text1.text) & "' where id= '" & Trim$(str!id) & "'"
End If
End If
If str.State = adStateOpen Then str.Close
str.Open strSQL, conn, adOpenStatic, adLockReadOnly
Set str = Nothing
DYtreechange:
Unload Me
FrmDepartmentSz.Tree_change
End Sub
Private Sub Form_Load()
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;" _
+ "User ID=sa;password=sa;Initial Catalog=ComSys;Data Source=127.0.0.1"
conn.Open
End Sub
我这段程序是用来添加和修改结点的,当修改结点时,如果父结点下有两个或两个以上的子结点时,程序运行就出现问题,提示出错是被注销的那一句,(str.MoveNext) 错误信息是:实时错误‘3704’对像关闭时操作不被允许,这是为什么呀