vb 模糊查询 不显示 5
PrivateSubCommand1_Click()DimCnAsNewADODB.ConnectionDimRSAsNewADODB.RecordsetL1.FullR...
Private Sub Command1_Click()
Dim Cn As New ADODB.ConnectionDim RS As New ADODB.Recordset
L1.FullRowSelect = True
L1.GridLines = True
L1.View = 3
L1.LabelEdit = lvwManual
Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\data.mdb;Persist Security Info=False"
Cn.Open
L1.ColumnHeaders.Clear
L1.ColumnHeaders.Add 1, , "ID", L1.Width / 10
L1.ColumnHeaders.Add 2, , "名称", L1.Width / 10 * 2
L1.ColumnHeaders.Add 3, , "电话", L1.Width / 10 * 2
Dim addlist As ListItem
Dim I As Integer
RS.Open "select * from 电话薄 where 姓名 like '*" & Text1.Text & "*'", Cn, 3, 1
Do While Not RS.EOF
Set addlist = L1.ListItems.Add(, , RS.Fields("id").Value)
addlist.SubItems(1) = RS.Fields("姓名")
addlist.SubItems(2) = RS.Fields("电话")
RS.MoveNext
Loop
RS.Close
Cn.Close
End Sub
模糊查询不显示查询结果RS.Open "select * from 电话薄 where 姓名 like '*" & Text1.Text & "*'", Cn, 3, 1
直接查询可显示结果RS.Open "select * from 电话薄 where 姓名='" & Text1.Text & "'", Cn, 3, 1
不知问题出在哪里?
需要vb ListView 模糊查询
模糊查询不显示查询结果RS.Open "select * from 电话薄 where 姓名 like '%" & Text1.Text & "%'", Cn, 3, 展开
Dim Cn As New ADODB.ConnectionDim RS As New ADODB.Recordset
L1.FullRowSelect = True
L1.GridLines = True
L1.View = 3
L1.LabelEdit = lvwManual
Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\data.mdb;Persist Security Info=False"
Cn.Open
L1.ColumnHeaders.Clear
L1.ColumnHeaders.Add 1, , "ID", L1.Width / 10
L1.ColumnHeaders.Add 2, , "名称", L1.Width / 10 * 2
L1.ColumnHeaders.Add 3, , "电话", L1.Width / 10 * 2
Dim addlist As ListItem
Dim I As Integer
RS.Open "select * from 电话薄 where 姓名 like '*" & Text1.Text & "*'", Cn, 3, 1
Do While Not RS.EOF
Set addlist = L1.ListItems.Add(, , RS.Fields("id").Value)
addlist.SubItems(1) = RS.Fields("姓名")
addlist.SubItems(2) = RS.Fields("电话")
RS.MoveNext
Loop
RS.Close
Cn.Close
End Sub
模糊查询不显示查询结果RS.Open "select * from 电话薄 where 姓名 like '*" & Text1.Text & "*'", Cn, 3, 1
直接查询可显示结果RS.Open "select * from 电话薄 where 姓名='" & Text1.Text & "'", Cn, 3, 1
不知问题出在哪里?
需要vb ListView 模糊查询
模糊查询不显示查询结果RS.Open "select * from 电话薄 where 姓名 like '%" & Text1.Text & "%'", Cn, 3, 展开
2个回答
展开全部
循环语句及其前两行改为如下,试试:
RS.Open "select * from 电话薄", Cn, 3, 1
rs.MoveFirst
Do While Not rs.EOF
If InStr(1, rs(姓名"), Me.text1.text, 1) > 0 then
Set addlist = L1.ListItems.Add()
addlist.Text = rs.Fields("id")
addlist.SubItems(1) = RS.Fields("姓名")
addlist.SubItems(2) = RS.Fields("电话")
End if
rs.MoveNext
Loop
注: 应用了Instr()函数
RS.Open "select * from 电话薄", Cn, 3, 1
rs.MoveFirst
Do While Not rs.EOF
If InStr(1, rs(姓名"), Me.text1.text, 1) > 0 then
Set addlist = L1.ListItems.Add()
addlist.Text = rs.Fields("id")
addlist.SubItems(1) = RS.Fields("姓名")
addlist.SubItems(2) = RS.Fields("电话")
End if
rs.MoveNext
Loop
注: 应用了Instr()函数
追答
我试了,用下面代码可以实现你所需的、
Dim Cn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
L1.ListItems.Clear
L1.FullRowSelect = True
L1.Gridlines = True
L1.View = 3
L1.LabelEdit = lvwManual
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\data.mdb"
Rs.Open "select * from 电话薄", Cn, 3, 1
L1.ColumnHeaders.Clear
L1.ColumnHeaders.Add 1, , "ID",L1.Width / 10
L1.ColumnHeaders.Add 2, , "名称", L1.Width / 10 * 2
L1.ColumnHeaders.Add 3, , "电话", L1.Width / 10 * 2
Dim addlist As ListItem
Dim I As Integer
Rs.MoveFirst
Do While Not Rs.EOF
If InStr(1, Rs("姓名"), Trim(Text1.Text)) > 0 Then
Set addlist = L1.ListItems.Add()
addlist.Text = Rs.Fields("id")
addlist.SubItems(1) = Rs.Fields("姓名")
addlist.SubItems(2) = Rs.Fields("电话")
End If
Rs.MoveNext
Loop
Rs.Close
Cn.Close
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
weicraft6 回答 显然可以 但是效率不高
RS.Open "select * from 电话薄 where instr(1,姓名, '" & Text1.Text & "')>0", Cn, 3, 1
比weicraft6 方式效率高,但是估计提问者是问为什么like 不能用 ,这个like我觉得微软做的不够好,会出莫名其的问题 “*”和“%”我都试过 在Access里和vb里同样的语句运行结果不一致
又测试了下 % 应该在vb里可以的
RS.Open "select * from 电话薄 where instr(1,姓名, '" & Text1.Text & "')>0", Cn, 3, 1
比weicraft6 方式效率高,但是估计提问者是问为什么like 不能用 ,这个like我觉得微软做的不够好,会出莫名其的问题 “*”和“%”我都试过 在Access里和vb里同样的语句运行结果不一致
又测试了下 % 应该在vb里可以的
追问
RS.Open "select * from 电话薄 where instr(1,姓名, '" & Text1.Text & "')>0", Cn, 3, 1
显示了全部信息,%在vb查不到信息
追答
我测试可以啊 你能把代码连同数据库发给我吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询