سؤال

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?

هل كانت مفيدة؟

المحلول

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 + "%")

نصائح أخرى

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

works for me (without ')

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top