程序功能:在文本框Text1中输入课程号,单击“查询”按钮Command1,在列表框List1中显示选修本课程的学生信息。如果没有找到,在列表框中显示“该课程当前无人报名”。按此要求将程序补充完整。
Private Sub command1_click()
Dim xh(1 to 40),xm(1 to 40) As String '学号和姓名的数组
Dim i,num as integer
Dim conn As New ADODB.Connection, rs As New ADODB.Recordset
Dim strSQL As String
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App.Path + "\student.accdb" '打开到数据库的链接
conn.Open
strSQL ="select xh,xm from data where '课程=&(Text1.Text) & '" '设置查询的SQL语句
Set rs.ActiveConnection = conn '设置rs的ActiveConnection属性,指定与其关联的数据库链接
rs.Open strSQL '打开记录集,将从表student中读取的结果集保存到记录集rs中
List1.Clear
num=0
Do while not rs.EOF
①
xh(num)=rs.Fields("xh")
xm(num)=rs.Fields("xm")
rs.MoveNext
loop
rs.Close
conn.close
set rs=nothing
set conn=nothing
For i=1 to num
②
Next i
if num=0 then list1.additem("该课程当前无人报名")
End Sub