前言:
組合查詢是機房的另乙個重點;涉及到的窗體有:學生基本資訊維護、學生上機資訊統計、操作員工作記錄。
邏輯:
問題及重點**:
1.呼叫函式的目的是使得漢字與表中字段進行轉化
例:sql語句的姓名應該是student name,而**中新增的是文字(combo3.additem 「姓名」)通過函式可以將兩者進行轉化
2.表中資訊清空:
通過加入mshflexgrid1.clear可以清空
3.實時錯誤」3021」的四種情況:
(出現這種錯誤就可以按照這四種情況一一進行排除)
1).查詢的資料庫記錄為空..可以用 rs.recordcount 來判斷資料是否等於0
2).查詢到資料後,用 del 命令刪除記錄後,再引用 fields 後會出現錯誤.
3).已經用movefirst 或用 moveprevious 命令 移動至資料庫開始後再用 moveprevious 命令.
4).已經用movelast 或用 movenext 命令 移動至資料庫開始後再用 movenext 命令.
感覺前兩種比較常見,通過新增如下**可以解決:
4.錯誤」94」 為nullif mrc.eof then
msgbox "查詢不到內容!"
exit sub
end if
在出錯的地方加入 & 」 「就可以解決;意思是或者為空值。
定義的函式**如下:
public
function field(i as
string) as
string
select
case i
case
"卡號"
field = "cardno"
...case
"餘額"
field = "recharge"
case
"或" field = "or"
case
"與" field = "and"
endselect
endfunction
總結:if
trim(combo1.text) = ""
ortrim(combo2.text) = ""
ortrim(text1.text) = ""
then
msgbox
"請將第一行內容填寫完整!", vbokonly, "提示"
exit
subelse
txtsql = txtsql & " " & field(combo1.text) & combo2.text & "'" & trim(text1.text) & "'"
ifcombo7.text
<> ""
then
'判斷第乙個組合關係是否選中
if combo3.text = "" or combo4.text = "" or text2.text = "" then
msgbox "請將第二行內容填寫完整!", vbokonly, "提示"
exit sub
else
txtsql = txtsql & "" & field(combo7.text) & " " & field(combo3.text) & combo4.text & "'
" & text2.text & "
'" if combo8.text <> "" then
if combo5.text = "" or combo6.text = "" or text3.text = "" then
msgbox "請將第三行內容填寫完整!", vbokonly, "提示"
exit sub
else
txtsql = txtsql & "" & field(combo8.text) & " " & field(combo5.text) & combo6.text & "'
" & text3.text & "
'" '將前三行的條件聯絡起來
endifend
ifend
ifend
ifend
if
txtsql = "select * from line_info" & " where" & txtsql
set mrc = executesql(txtsql, msgtext)
if mrc.eof
then
msgbox
"查詢不到內容!"
exit
subend
if'將查詢內容顯示在**控制項中
with mshflexgrid
.rows = 2 '
2行 .cellalignment = 4
.textmatrix(0, 0) = "卡號"
.textmatrix(0, 1) = "姓名"
.textmatrix(0, 2) = "上機日期"
.textmatrix(0, 3) = "上機時間"
.textmatrix(0, 4) = "下機日期"
.textmatrix(0, 5) = "下機時間"
.textmatrix(0, 6) = "消費金額"
.textmatrix(0, 7) = "餘額"
'判斷是否移動到資料集物件的最後一條記錄
do while not mrc.eof
.rows = .rows + 1
.cellalignment = 4
.textmatrix(.rows - 2, 0) = mrc.fields(0)
.textmatrix(.rows - 2, 1) = mrc.fields(2)
.textmatrix(.rows - 2, 2) = mrc.fields(5)
.textmatrix(.rows - 2, 3) = mrc.fields(6)
.textmatrix(.rows - 2, 4) = mrc.fields(7)
.textmatrix(.rows - 2, 5) = mrc.fields(8)
.textmatrix(.rows - 2, 6) = mrc.fields(10) & " "
.textmatrix(.rows - 2, 7) = mrc.fields(11)
'移動到下一條記錄
mrc.movenext
loop
endwith
mrc.close
個人覺得組合查詢就是一條sql語句。
txtsql = 「select * from line_info」 & 」 where」 & txtsql
txtsql = txtsql & 」 」 & field(combo1.text) & combo2.text & 「』」 & trim(text1.text) & 「』」
比如:通過第一行查詢姓名為1的所有資訊。
field(combo1.text)就是姓名(sql語句中漢字無法識別,通過函式轉化為student_name),combo2.text就是」=」,trim(text1.text)就是1
機房收費系統之 組合查詢
總是把它想象的很難。所以才會畏懼。其實只要邏輯清晰,就好了。private function fieldname strfieldname as string as string 將程式的字對應為資料庫 select case strfieldname case 卡號 fieldname cardn...
機房收費系統 組合查詢
機房收費系統在磕磕絆絆中過來了,這期間遇到問題,解決問題,最後收穫的特別多,在敲得過程中,不斷的學習新知識,應該說組合查詢是收費系統的乙個小難點了吧,起初我是真的不知道該從 下手,總是有種剪不斷理還亂的感覺,分析分析就繞進去了,我總是把問題想的很複雜,其實只要一句 語句,一切都解決了,根本用不到好多...
機房收費系統 組合查詢
關於組合查詢,真的是乙個令人頭疼的東西,但是當自己突然間的做出來時,卻莫名的有種貌似又不是很難得感覺。昨天弄了整整一下午,今天的下午終於在除錯了兩個小時做出來了。首先是查到了一些關於組合查詢的部落格,有乙個共同的特點就是都要獲得使用者所選的欄位名並轉化成資料庫表中的欄位名,這樣實現了人機共同語言的轉...