?? 140.txt
字號(hào):
在數(shù)據(jù)庫(kù)應(yīng)用中, 經(jīng)常要?jiǎng)討B(tài)生成 Select 語(yǔ)句,典型的情況:
SqlString = "Select * from myBas where Name = '" & Text1 & "'"
好啦, 問題出現(xiàn)了, 如果在錄入的 Text1 中有一個(gè)單引號(hào),結(jié)果是把 SqlString 發(fā)給數(shù)據(jù)庫(kù)時(shí), 將出錯(cuò)!
其實(shí)要做的防范很簡(jiǎn)單, 增加一個(gè)函數(shù):
FUNCTION CheckString (s) as String
pos = InStr(s, "'")
While pos > 0
s = Mid(s, 1, pos) & "'" & Mid(s, pos + 1)
pos = InStr(pos + 2, s, "'")
Wend
CheckString="'" & s & "'"
END FUNCTION
以后在動(dòng)態(tài)生成 Select 語(yǔ)句, 使用:
SqlString = "Select * from myBas where Name = " & CheckString(Text1)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -