Pergunta

I've looked around but can't seem to find a solution to parametrize a query in VBA using ADO.

I'm looking to achieve something like:

.CommandText = "SELECT * FROM table WHERE F_Name LIKE '%?%'"
.Parameters.Append .CreateParameter("p1", adVarChar, adInputParam, 255, strFname)

Could anyone help with how to apply append a parameter in the above manor?

Foi útil?

Solução

You could append and prepend the % symbol to your string variable before you pass it into CreateParameter

.CommandText = "SELECT * FROM table WHERE F_Name LIKE '?'"
.Parameters.Append .CreateParameter("p1", adVarChar, adInputParam, 255, "%" + strFname + "%")

Outras dicas

.CommandText = "SELECT * FROM table WHERE F_Name LIKE ?"
.Parameters.Append .CreateParameter("p1", adVarChar, adInputParam, 255, "%" + strFname + "%")

works for me (without ')

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top