vb查询access数据库只显示一条记录 20

OptionExplicitDimconnAsADODB.ConnectionDimrsAsADODB.RecordsetDimcmdAsADODB.CommandPri... Option Explicit
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command

Private Sub Command1_Click()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set cmd = New ADODB.Command
conn.ConnectionString = "provider=Microsoft.jet.OLEDB.4.0;" & "data source=" & App.Path & "\database.mdb;" & "persist security info=false"
conn.Open
cmd.CommandType = adCmdText
cmd.ActiveConnection = conn
If Combo1.Text = "" Then
MsgBox "条件不能为空值,请重新输入"
ElseIf Combo1.Text = "客户" Then
cmd.CommandText = "select*from test where 客户='" & Text16.Text & "'"
ElseIf Combo1.Text = "件数" Then
cmd.CommandText = "select*from test where 件数='" & Text16.Text & "'"
ElseIf Combo1.Text = "车牌号" Then
cmd.CommandText = "select*from test where 车牌号='" & Text16.Text & "'"
ElseIf Combo1.Text = "驾驶员" Then
cmd.CommandText = "select*from test where 驾驶员='" & Text16.Text & "'"
ElseIf Combo1.Text = "驾驶员电话" Then
cmd.CommandText = "select*from test where 驾驶员电话='" & Text16.Text & "'"
End If
Set rs = cmd.Execute
Set MSHFlexGrid1.DataSource = rs
rs.Close
conn.Close
End Sub

Private Sub Form_Load()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionString = "provider=Microsoft.jet.OLEDB.4.0;" & "data source=" & App.Path & "\database.mdb;" & "persist security info=false"
conn.Open
rs.Open "test", conn, , adCmdTable
Set MSHFlexGrid1.DataSource = rs
rs.Close
conn.Close
Combo1.AddItem "客户"
Combo1.AddItem "电话"
Combo1.AddItem "件数"
Combo1.AddItem "车牌号"
Combo1.AddItem "驾驶员"
Combo1.AddItem "驾驶员电话"
End Sub
展开
 我来答
清晰且通达灬福音z
2015-12-08 · 超过48用户采纳过TA的回答
知道小有建树答主
回答量:104
采纳率:0%
帮助的人:81.2万
展开全部
select*from test where 客户='" & Text16.Text &

这句话的意思是,显示所有字段,但是字段 客户内容等于text16.text值的信息。肯定是一条记录,除非在客户字段中,出现多个等于text16.text值。才会出现多条记录。
如果你要显示所有的客户字段信息:使用语句-
select 客户 from test
追问
能给一个完整的语句吗?
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式