某學(xué)校開(kāi)設(shè)多樣化選修課程,學(xué)生可以根據(jù)個(gè)人興趣和特長(zhǎng)選擇選修課.假設(shè)每門選修課的選課人數(shù)不超過(guò)40,學(xué)生選課的相關(guān)信息存放在數(shù)據(jù)庫(kù)文件“student.accdb”的data表中,選課查詢程序運(yùn)行時(shí)界面如圖所示.
程序功能:在文本框Text1中輸入課程號(hào),單擊“查詢”按鈕Command1,在列表框List1中顯示選修本課程的各學(xué)生信息.如果沒(méi)有找到,在列表框中顯示“該課程當(dāng)前無(wú)人報(bào)名”.按此要求將程序補(bǔ)充完整.
Private Sub Command1_Click ( ?。?br />Dim xh(1to 40),xm(1to 40)As String'學(xué)號(hào)和姓名的數(shù)組
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;DataSource=”+App.Path+“\student.accdb”'打開(kāi)到數(shù)據(jù)庫(kù)的鏈接
conn.Open
strSQL=“select xh,xm from data where課程=‘&(Text1.Text)&’”'設(shè)置查詢的SQL語(yǔ)句
Set rs.ActiveConnection=conn'設(shè)置rs的ActiveConnection屬性,指定與其關(guān)聯(lián)的數(shù)據(jù)庫(kù)鏈接
rs.OpenstrSQL'打開(kāi)記錄集,將從表data中讀取的結(jié)果集保存到記錄集rs中
List1.Clear
num=0
DO while not rs.EOF
num=num+1
num=num+1
xh(num)=rs.Fields(“xh”)
xm(hum)=rs.Fields(“xm”)
rs.MoveNext
loop
rs.Close
conn.close
set rs=nothing
set conn=nothing
For i=1to num
List1.a(chǎn)dditem (xh(i))+“”+xm(i)
List1.a(chǎn)dditem (xh(i))+“”+xm(i)
Next i
if num=0then
List1.a(chǎn)dditem(“該課程當(dāng)前無(wú)人報(bào)名”)
End Sub
(1)程序中①橫線處應(yīng)填入 num=num+1
num=num+1
.
(2)程序中②橫線處應(yīng)填入 List1.a(chǎn)dditem (xh(i)+“”+xm(i))
List1.a(chǎn)dditem (xh(i)+“”+xm(i))
.