機房收費系統之 組合查詢

2021-06-19 01:18:30 字數 3216 閱讀 5908

總是把它想象的很難。所以才會畏懼。其實只要邏輯清晰,就好了。

private function fieldname(strfieldname as string) as string

'將程式的字對應為資料庫

select case strfieldname

case "卡號"

fieldname = "cardno"

case "姓名"

fieldname = "studentname"

case "上級時間"

fieldname = "ontime"

case "上級日期"

fieldname = "ondate"

case "與"

fieldname = "and"

case "或"

fieldname = "or"

case "機房號"

fieldname = "computer"

end select

private sub command1_click()

dim mrc as adodb.recordset

dim txtsql as string

dim msgstring as string

dim txtsql1 as string

dim txtsql2 as string

dim txtsql3 as string

txtsql1 = "select * from online where " & " " & fieldname(cmbletter1.text) & cmboperate1.text & "'" & txtenquire1 & "'"

txtsql2 = "select * from online where " & " " & fieldname(cmbletter1.text) & cmboperate1.text & "'" & txtenquire1.text & "'" + fieldname(cmbcombination1.text) & " " & fieldname(cmbletter2.text) & cmboperate2.text & "'" & txtenquire2 & "'"

txtsql3 = "select * from online where " & " " & fieldname(cmbletter1.text) & cmboperate1.text & "'" & txtenquire1.text & "'" & " " & fieldname(cmbcombination1.text) & " " & _

fieldname(cmbletter2.text) & cmboperate2.text & "'" & txtenquire2.text & "'" & " " & fieldname(cmbcombination1.text) & " " & _

fieldname(cmbletter3.text) & cmboperate3.text & "'" & txtenquire3 & "'"

'---------------------------------------------當有一種條件時----------

if not testtxt(cmbcombination1.text) then '

txtsql = txtsql1

else ' ------------------------當有兩種條件時-----

if not testtxt(cmbletter2.text) or not testtxt(cmboperate2.text) or not testtxt(txtenquire2.text) then

msgbox "請輸入完整的查詢條件", vbokonly + vbexclamation, "提示"

else

if not testtxt(cmbcombination2.text) then '情況2 組合2為空

txtsql = txtsql2

else '--------------------------以下是:兩個組合關係都有內容

if not testtxt(cmbletter3.text) or not testtxt(cmboperate3.text) or not testtxt(txtenquire3.text) then

msgbox "請輸入完整的查詢條件", vbokonly + vbexclamation, "提示"

else

txtsql = txtsql3

end if

end if

end if

end if

end if

'開始執行sql-------------------------------------------

set mrc = executesql(txtsql, msgstring)

if mrc.eof then

msgbox "尚無記錄!", vbokonly + vbexclamation, "提示"

else

with msflexgrid1

.rows = 1

.cols = 5

.cellalignment = 4

.textmatrix(0, 0) = "卡號"

.textmatrix(0, 1) = "姓名"

.textmatrix(0, 2) = "上機日期"

.textmatrix(0, 3) = "上機時間"

.textmatrix(0, 4) = "機房號"

end with

do while not mrc.eof

with msflexgrid1

.rows = .rows + 1

.textmatrix(.rows - 1, 0) = mrc.fields(0)

.textmatrix(.rows - 1, 1) = mrc.fields(3)

.textmatrix(.rows - 1, 2) = mrc.fields(6)

.textmatrix(.rows - 1, 3) = mrc.fields(7)

.textmatrix(.rows - 1, 4) = mrc.fields(8)

mrc.movenext

end with

loop

end if

mrc.close

end sub

機房收費系統之組合查詢

前言 組合查詢是機房的另乙個重點 涉及到的窗體有 學生基本資訊維護 學生上機資訊統計 操作員工作記錄。邏輯 問題及重點 1.呼叫函式的目的是使得漢字與表中字段進行轉化 例 sql語句的姓名應該是student name,而 中新增的是文字 combo3.additem 姓名 通過函式可以將兩者進行轉...

機房收費系統 組合查詢

機房收費系統在磕磕絆絆中過來了,這期間遇到問題,解決問題,最後收穫的特別多,在敲得過程中,不斷的學習新知識,應該說組合查詢是收費系統的乙個小難點了吧,起初我是真的不知道該從 下手,總是有種剪不斷理還亂的感覺,分析分析就繞進去了,我總是把問題想的很複雜,其實只要一句 語句,一切都解決了,根本用不到好多...

機房收費系統 組合查詢

關於組合查詢,真的是乙個令人頭疼的東西,但是當自己突然間的做出來時,卻莫名的有種貌似又不是很難得感覺。昨天弄了整整一下午,今天的下午終於在除錯了兩個小時做出來了。首先是查到了一些關於組合查詢的部落格,有乙個共同的特點就是都要獲得使用者所選的欄位名並轉化成資料庫表中的欄位名,這樣實現了人機共同語言的轉...