VB+ACCESS使用LIKE查询出现错误(有变量)
高手们帮看看:别的查询都没事,到用like的就不行了
Sql = "SELECT * FROM tyi1 WHERE names LIKE '% " & Text8.Text & "% ' "
rs.Open Sql, cnn, adOpenDynamic, adLockPessimistic
If rs.RecordCount > 0 Then
Form1.Label1.Caption = rs.Fields(1).Value
后面就略了,报错的是rs.open那句,提示Run-time error '-2147217913(80040007) '(里面数字不重要吧?)
method 'open ' of object '_Recordset ' failed
使用adodb连接。tyi1是表名,names是列名。想通过text8.text的内容模糊查询数据库并显示给label
大家看看怎么回事?
[解决办法]
Sql = "SELECT * FROM [tyi1] WHERE [names] LIKE '* " & Text8.Text & "* ' "
?? names 是关键字??