请问access模糊查询
VB.NET中我拉了一个datagrid控件,绑定了dataset数据:
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dbname As String
dbname = Server.MapPath("db1.mdb")
myConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" & dbname)
myConnection.Open()
Label1.Text = "连接数据库成功"
myCommand = New OleDbCommand("select * from table1 where name like ' * " & TextBox1.Text & " * '",myConnection)
DataGrid1.DataSource = myCommand.ExecuteReader()
DataGrid1.DataBind()
已经成功连接到数据库,为什么搜索不到匹配的记录?数据库中有很多条可以匹配的.
我试过的无效的代码:
select * from tabel1 where name like ' * TextBox1.Text * ' '换成双引号也不行
select * from tabel1 where name like ' % TextBox1.Text % ' '换成双引号也不行
select * from tabel1 where name like ' * " & TextBox1.Text & " * ' '换成双引号也不行
select * from tabel1 where name like ' % " & TextBox1.Text & " % ' '换成双引号也不行
select * from tabel1 where name like '*小明*' '最后没法了,连变量都不用了还是不行
select * from tabel1 where name like '*小明*' '最后没法了,连变量都不用了还是不行
select * from tabel1 where name like '*小明*' '最后没法了,连变量都不用了还是不行
究竟是什么原因呢?网络上查找到都说access模糊查询语法就是 select * from 表 where 字段 like '* 查询内容*' [*、%是通配符],难道不对吗?
问题点数:20、回复次数:6Top
1 楼scriptkidde()回复于 2006-06-03 03:31:32 得分 0
已解决,非程序问题
是SQL查询模式问题
具体解决:
http://office.microsoft.com/assistance/hfws.aspx?AssetID=HP030702012052Top
2 楼wangtiecheng(不知不为过,不学就是错!)回复于 2006-06-03 11:43:32 得分 0
查询中用*
VBA代码中SQL语句用%
Top
3 楼changechange(http://access911.net 是我的个人网站,欢迎光临)回复于 2006-07-26 12:04:33 得分 20
换 ANSI 92 规范后压缩修复数据库,重新打开,用 like '%" & textbox.text & "%'Top
4 楼wwwwb()回复于 2006-07-26 13:04:35 得分 0
access 查询中用*
VBA ado 代码中SQL语句用%Top
5 楼changechange(http://access911.net 是我的个人网站,欢迎光临)回复于 2006-07-26 14:19:27 得分 0
换 ANSI 92 规范后压缩修复数据库,重新打开,用 like '%" & textbox.text & "%'
Top
6 楼xzyan80(up)回复于 2006-08-15 13:10:50 得分 0
原来这样啊Top




