各位大神,現在有個問題,我需要在SQL陳述句中模糊查詢。根據text9控制元件中的值 來輸出相應的資料 但是如下代碼 要么顯示表("select * from kcm01")全部內容 要么就是 顯示ErrMsg的內容
Public Function cc(Index, SQL) As Boolean
If Rsbdata.State = adStateOpen Then
Rsbdata.Close
End If
On Error GoTo ErrMsg
Dim strSQL As String
strSQL = "select * from kcm01"
If Text9 = " " Then '單號
MsgBox "請輸入品牌代碼!"
Else
strSQL = strSQL & " where kcckdm like " & " '%" & Text9 & "%'"
End If
Rsbdata.CursorLocation = adUseClient
Rsbdata.Open strSQL, Consb
cc = True
Exit Function
ErrMsg:
MsgBox "陳述句執行失敗! strSQL, 16"
cc = False
End Function
uj5u.com熱心網友回復:
建議先手動在查詢分析器中執行相關SQL陳述句,確定無誤后再移植到代碼中。uj5u.com熱心網友回復:
把strSQL值Debug出來,放到資料庫里去查一下,看有什么錯誤。uj5u.com熱心網友回復:
strSQL = "select * from kcm01 where kcckdm like '%" & Text9.text & "%'"uj5u.com熱心網友回復:
1、檢查 Consb 是否正常2、檢查 strSQL 是否正確
3、set Rsbdata=https://bbs.csdn.net/topics/ Consb.execute( strSQL)
4、sql 中 like 效率低 尤其是像這種 ‘%aaaaa%’
......
uj5u.com熱心網友回復:
strSQL = strSQL & " where kcckdm like " & " '%" & Text9 & "%'"修改為:
strSQL = strSQL & " where kcckdm Like '%" & Text9.Text & "%' "
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/79590.html
標籤:控件
上一篇:請教高手,VB小游戲的網路互動需要怎么撰寫?告知思路或給案例,謝謝!
下一篇:小白請教VB
