请教VB高手:数据库中数据查询的问题

来源:百度知道 编辑:UC知道 时间:2024/07/02 17:11:08
我是一名小学教师,在这里请教VB高手:我用Access做一张表(五年级),只有一个字段(词语)用用MSFlexGrid控件显示整个表的数据。想让MSFlexGrid控件在点击command1后显示包含有strSTR的内容的数据,运行后已能显示出可个表的数据
Private Sub Command1_Click()
Command1.Visible = False

Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str1 As String
Dim Str2 As String
Dim Str3 As String
Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
Str2 = "Data Source=d:\My Documents\db1.mdb;"
Str3 = "Jet OLEDB:Database Password="
conn.Open Str1 & Str2 & Str3

Dim strSTR As String
strSqL = "select * from 五年级 where 词语 like ' % Trim(strSTR) %' "
rs.Open strSqL, conn, 3, 3

Command1.Visible = True
End Sub
点击按钮后还是显示整个表的内容

请问:这是怎么回事?

strSqL = "select * from 五年级 where 词语 like ' % Trim(strSTR) %' "
改成:
strSqL = "select * from 五年级 where 词语 like '%' + Trim(" & strSTR & ") +'%' " 试试。

如果还不可以的话联系我的百度hi。

---
以上,希望对你有所帮助

strSqL = "select * from 五年级 where 词语 like '' %'+ Trim(strSTR)+' %'' "

like ' % Trim(strSTR) %' "
上面这个改一下试试
like ' %“& Trim(strSTR)&” %' "

其实Access用Adodc连接数据库,直接用DataGrid控件显示更简洁,将DataGrid的DataSource连接到数据库就可以了。数据库可采取绑定的方式。
查询:
adodc1.recordset.filter="词语='" & Text1.text &"""