我有一个名为 lvsubject 的两个列表视图和 lvcurchecklist 。我还有一个按钮。此按钮会将lvsubject中的选定项目加载到lvcurchecklist。
Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
Dim ctr As Integer
For ctr = 0 To lvsubject.Items.Count - 1
If lvsubject.Items(ctr).Checked = True Then
sSql = "Select * from tblsubject where subid ='" & lvsubject.Items(ctr).SubItems(2).Text & "'"
execSQL(sSql, False)
If RD.Read Then
With lvcurchecklist.Items.Add(RD(0), 0)
.SubItems.Add(RD(2))
.SubItems.Add(RD(3))
End With
End If
Else
sSql = "Select * from tblsubject where subid ='" & lvsubject.SelectedItems(ctr).SubItems(2).Text & "'"
execSQL(sSql, False)
If RD.Read Then
With lvcurchecklist.Items.Add(RD(0), 0)
.SubItems.Add(RD(2))
.SubItems.Add(RD(3))
End With
End If
End If
Next
ctr += 1
End Sub
抛出错误
InvalidArgument ='1'的值对'index'无效。
在这一行:
sSql = "Select * from tblsubject where subid ='" & lvsubject.SelectedItems(ctr).SubItems(2).Text & "'"
tblsubject:
subid -holds主题id
yrlevelid -holds年级id
主题代码 - 保留主题的代码
subjectdesc-保留对主题的描述
单元