有关模糊查询的问题
我拉了一个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、回复次数:4Top
1 楼scriptkidde()回复于 2006-06-03 03:30:09 得分 0
已解决,非程序问题
是SQL模式问题,具体解决:
http://office.microsoft.com/assistance/hfws.aspx?AssetID=HP030702012052
Top
2 楼stone_soup(夜不打拾)回复于 2006-06-03 07:41:51 得分 0
接分Top
3 楼amandag(高歌)回复于 2006-06-03 07:50:35 得分 0
真快Top
4 楼pinion()回复于 2006-06-03 11:06:36 得分 0
like '%" & textbox1.text & "%'Top




