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 展开
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 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询