【正文】
ariant, ByVal LastCol As Integer)book_num = (0).CellValue()panduan = (7).CellValue()End SubPrivate Sub Form_Load()Dim rs_find As New Dim sql As Stringsql = select * from 圖書類別 sql, conn, adOpenKeyset, adLockPessimisticIf Not Then Do While Not (0) Loop = 0End IfEnd Sub 查詢完畢后,輸出查詢結(jié)果,如圖24所示?! ★@示目錄 (6) 用戶登錄子窗體代碼 在本項(xiàng)目中,用戶登錄子窗體是運(yùn)行的第一個界面,它的作用是檢查用戶名和密碼是否正確。由于用戶的資料是存放在數(shù)據(jù)庫中,所以在啟動該子窗體時,就已經(jīng)連接了數(shù)據(jù)庫。其代碼如下: Private Sub Form_Load() Dim connectionstring As String connectionstring = provider=。 amp。 _ data source= connectionstring t = 0 End Sub “確定”按鈕的作用是檢查輸入的數(shù)據(jù)是否與數(shù)據(jù)庫中的數(shù)據(jù)一致?! rivate Sub Command1_Click() Dim sql As String Dim rs_login As New If Trim() = Then ’ 判斷輸入的用戶名是否為空MsgBox 沒有這個用戶, vbOKOnly + vbExclamation, Else sql = select * from 系統(tǒng)管理 where 用戶名=’ amp。 amp。 ’ sql, conn, adOpenKeyset, adLockPessimistic If = True Then MsgBox 沒有這個用戶, vbOKOnly + vbExclamation, Else ’ 檢驗(yàn)密碼是否正確 用戶名和密碼通過后,要關(guān)閉本窗體并打開主窗體?! f Trim((1)) = Trim() Then userID = userpow = (2) Unload Me Else MsgBox 密碼不正確, vbOKOnly + vbExclamation, End If End If End If ’ 只能輸入3次 t = t + 1 If t = 3 Then Unload Me End If Exit Sub End Sub (7)查詢借書信息如圖25如圖27代碼如下:Option ExplicitPrivate Sub Command1_Click()Dim sql As StringDim rs_find As New If = True Then sql = select * from 書籍信息 where 是否被借出=39。是39。End IfIf = True Then sql = select * from 書籍信息 where 是否被借出=39。否39。End IfIf = True Then sql = select * from 借閱信息 where 讀者姓名=39。 amp。 amp。 39。End If = adUseClient sql, conn, adOpenKeyset, adLockPessimistic = False = False = False Set = rs_findEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Sub Frame2_DragDrop(Source As Control, X As Single, Y As Single)End Sub此板塊,可以查詢已經(jīng)借出的書,沒有借出的書,也可以按讀者姓名查詢?。。。?)還書信息如圖26如圖26代碼如下:Option ExplicitDim findform As BooleanPrivate Sub Combo1_Click() = End SubPrivate Sub Combo2_Click() = End SubPrivate Sub Combo3_Click() = End SubPrivate Sub Combo4_Click() = End SubPrivate Sub Command1_Click()Dim rs_reader As New Dim sql As Stringfindform = Truesql = select * from 借閱信息 where 讀者姓名=39。 amp。 amp。 39。 = adUseClient sql, conn, adOpenKeyset, adLockPessimisticSet = rs_reader = False = False = FalseEnd SubPrivate Sub Command2_Click()Dim rs_book As New Dim sql As Stringfindform = Falsesql = select * from 借閱信息 where 書籍編號=39。 amp。 amp。 39。 = adUseClient sql, conn, adOpenKeyset, adLockPessimisticSet = rs_book = False = False = FalseEnd SubPrivate Sub Command3_Click()Dim book_num As StringDim reader_num As StringDim answer As StringDim rs_back As New Dim sql As StringOn Error GoTo delerrorbook_num = (3).CellValue()reader_num = (1).CellValue()answer = MsgBox(確定要還這本書嗎?, vbYesNo, )If answer = vbYes Then sql = select * from 借閱信息 where 書籍編號=39。 amp。 book_num amp。 39。 = adUseClient sql, conn, adOpenKeyset, adLockPessimistic sql = select * from 書籍信息 where 書籍編號=39。 amp。 book_num amp。 39。 = adUseClient sql, conn, adOpenKeyset, adLockPessimistic (7) = 否 sql = select * from 讀者信息 where 讀者編號=39。 amp。 reader_num amp。 39。 = adUseClient sql, conn, adOpenKeyset, adLockPessimistic (8) = (8) 1 If findform = True Then Command1_Click Else Command2_Click End If MsgBox 成功刪除!, vbOKOnly + vbExclamation, = FalseElse Exit SubEnd Ifdelerror:If 0 Then MsgBox End IfEnd SubPrivate Sub Command4_Click()Unload MeEnd SubPrivate Sub Form_Load()Dim rs_reader As New Dim rs_book As New Dim sql As Stringsql = select * from 讀者信息 = adUseClient sql, conn, adOpenKeyset, adLockPessimisticIf Not Then Do While Not (1) (0) LoopEnd Ifsql = select * from 借閱信息 = adUseClient sql, conn, adOpenKeyset, adLockPessimisticIf Not Then Do While Not (3) (4) LoopEnd IfEnd Sub