VB 利用like进行模糊查询

来源:百度知道 编辑:UC知道 时间:2024/05/28 04:28:04
vb所连接的数据库是Access2003,采用Adodc1直接绑定,现要用like进行模糊查询,其他的模糊查询方式亦可。

'首先打开数据库并选Tools-Database Utilities-Convert Database-To Access 2002-2003 file Format.另存名称。
'实例:
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\数据库名.mdb"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "Select * From 资料表 where 字段 like'%" & Text1.Text & "%'"
Adodc1.Refresh

Set DataGrid1.DataSource = Adodc1
DataGrid1.Refresh
End Sub

sq = "Select * From test where swname like'%" & Text1.Text & "%' order by swname"