简体   繁体   English

VB6-ADO-像参数化查询-Access DB

[英]VB6 - ADO - LIKE Paramaterized Query - Access DB

Using ADO via VB6, i'm having a hard time using the LIKE command on my access file paramaterized query. 通过VB6使用ADO,我很难在访问文件参数化查询中使用LIKE命令。

    Dim strSQL As String
    strSQL = "SELECT * FROM [MY_TABLE] WHERE [MY_TEXT_COLUMN_NAME] LIKE %?%"

Dim conn As ADODB.Connection
Set conn = New ADODB.Connection

    conn.ConnectionString = _
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DATABASE_PATH & ";Persist Security Info=False;"

    conn.Open

Dim adoCommand As ADODB.Command
Set adoCommand = New ADODB.Command

    With adoCommand
        .ActiveConnection = conn
        .CommandType = adCmdText
        .CommandText = strSQL
        .Prepared = True
        .Parameters.Append .CreateParameter(, adVarChar, adParamInput, 255, strMYTEXT)

        Dim rs As ADODB.Recordset
        Set rs = .Execute
    End With

returns an empty record set not sure the wildcards are needed here, but i just couldn't find the right way to place them. 返回一个空的记录集,不确定在这里是否需要通配符,但我只是找不到正确的方式放置它们。

Found it. 找到了。

strSQL = "SELECT * FROM [MY_TABLE] WHERE [MY_TEXT_COLUMN_NAME] LIKE %?%"

should actually be 实际上应该是

strSQL = "SELECT * FROM [MY_TABLE] WHERE [MY_TEXT_COLUMN_NAME] LIKE '%' + ? + '%'"

that solved it. 解决了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM