VB查询ACCESS数据库内容
来源:互联网 发布:sopcast这款网络电视 编辑:程序博客网 时间:2024/05/29 02:18
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Private Sub Command2_Click()
On Error Resume Next
'Adodc2.RecordSource = "select * from A2 where 人口=" & Trim(Text5.Text)
Adodc2.RecordSource = "select * from A2 where 人口>=" & Text5.Text & " And 人口 <= " & Text6.Text & ""
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
End Sub
Private Sub Command3_Click()
Adodc2.RecordSource = "select * from A2 where 省份='" & Text7.Text & "'"
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
End Sub
Private Sub Command4_Click()
'Adodc2.RecordSource = "select * from A2 where 时间 = #2002/7/5#"
'Adodc2.RecordSource = "select * from A2 where 时间 > #2000/1/1# and 时间< #2001/1/2#"
'Adodc2.RecordSource = "select * from A2 where 时间 between #2000/1/1# and #2000/2/2#"
'Adodc2.RecordSource = "select * from A2 where 时间 =#" & Format(Text8.Text, "yyyy/mm/dd") & "#"
Adodc2.RecordSource = "select * from A2 where
时间 between #" & Format(Text8.Text, "yyyy/mm/dd") & "# and #" & Format(Text9.Text, "yyyy/mm/dd") & "# "
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
End Sub
Private Sub Command5_Click()
'Adodc2.RecordSource = "select * from A2 where 时间 =#" & Format(DTPicker1.Value, "yyyy/mm/dd") & "#"
'Adodc2.RecordSource = "select * from A2 where 时间 >#" & Format(DTPicker1.Value, "yyyy/mm/dd") & "# and 时间 <#" & Format(DTPicker2.Value, "yyyy/mm/dd") & "# "
Adodc2.RecordSource = "select * from A2 where 时间 between #" & Format(DTPicker1.Value, "yyyy/mm/dd") & "# and #" & Format(DTPicker2.Value, "yyyy/mm/dd") & "# "
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
End Sub
Private Sub Form_Load()
cnn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\db_k1.mdb" '连接数据库
Set cmd.ActiveConnection = cnn
Me.WindowState = 2
Adodc1.CommandType = adCmdText
Adodc2.CommandType = adCmdText
End Sub
Private Sub Command1_Click() '单击"查询"按钮
On Error GoTo err_1 '如果发生错误,则去执行err_1后面的语句
cmd.CommandText = "select * from A2 where 城市='" & Text1.Text & "'" '查询文本框1中的内容
'cmd.CommandType = adCmdText
cmd.CommandTimeout = 15
Set rs = cmd.Execute
Text2.Text = rs.Fields("省份")
Text3.Text = rs.Fields("城市")
Text4.Text = rs.Fields("人口")
Adodc1.Recordset.MoveFirst
'Adodc1.Recordset.Find "省份=" & Text2.Text
'Adodc1.Recordset.Find "城市 = '苏州'"
Adodc1.Recordset.Find "城市= '" & Text3.Text & "'"
Adodc2.RecordSource = "select * from A2 where 城市='" & Text3.Text & "'"
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
Exit Sub
err_1:
MsgBox "未找到你所查询的结果"
End Sub
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command
Private Sub Command2_Click()
On Error Resume Next
'Adodc2.RecordSource = "select * from A2 where 人口=" & Trim(Text5.Text)
Adodc2.RecordSource = "select * from A2 where 人口>=" & Text5.Text & " And 人口 <= " & Text6.Text & ""
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
End Sub
Private Sub Command3_Click()
Adodc2.RecordSource = "select * from A2 where 省份='" & Text7.Text & "'"
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
End Sub
Private Sub Command4_Click()
'Adodc2.RecordSource = "select * from A2 where 时间 = #2002/7/5#"
'Adodc2.RecordSource = "select * from A2 where 时间 > #2000/1/1# and 时间< #2001/1/2#"
'Adodc2.RecordSource = "select * from A2 where 时间 between #2000/1/1# and #2000/2/2#"
'Adodc2.RecordSource = "select * from A2 where 时间 =#" & Format(Text8.Text, "yyyy/mm/dd") & "#"
Adodc2.RecordSource = "select * from A2 where
时间 between #" & Format(Text8.Text, "yyyy/mm/dd") & "# and #" & Format(Text9.Text, "yyyy/mm/dd") & "# "
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
End Sub
Private Sub Command5_Click()
'Adodc2.RecordSource = "select * from A2 where 时间 =#" & Format(DTPicker1.Value, "yyyy/mm/dd") & "#"
'Adodc2.RecordSource = "select * from A2 where 时间 >#" & Format(DTPicker1.Value, "yyyy/mm/dd") & "# and 时间 <#" & Format(DTPicker2.Value, "yyyy/mm/dd") & "# "
Adodc2.RecordSource = "select * from A2 where 时间 between #" & Format(DTPicker1.Value, "yyyy/mm/dd") & "# and #" & Format(DTPicker2.Value, "yyyy/mm/dd") & "# "
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
End Sub
Private Sub Form_Load()
cnn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\db_k1.mdb" '连接数据库
Set cmd.ActiveConnection = cnn
Me.WindowState = 2
Adodc1.CommandType = adCmdText
Adodc2.CommandType = adCmdText
End Sub
Private Sub Command1_Click() '单击"查询"按钮
On Error GoTo err_1 '如果发生错误,则去执行err_1后面的语句
cmd.CommandText = "select * from A2 where 城市='" & Text1.Text & "'" '查询文本框1中的内容
'cmd.CommandType = adCmdText
cmd.CommandTimeout = 15
Set rs = cmd.Execute
Text2.Text = rs.Fields("省份")
Text3.Text = rs.Fields("城市")
Text4.Text = rs.Fields("人口")
Adodc1.Recordset.MoveFirst
'Adodc1.Recordset.Find "省份=" & Text2.Text
'Adodc1.Recordset.Find "城市 = '苏州'"
Adodc1.Recordset.Find "城市= '" & Text3.Text & "'"
Adodc2.RecordSource = "select * from A2 where 城市='" & Text3.Text & "'"
Adodc2.Refresh
Set DataGrid2.DataSource = Adodc2
Exit Sub
err_1:
MsgBox "未找到你所查询的结果"
End Sub
0 0
- VB查询ACCESS数据库内容
- VB.NET ACCESS数据库SQL查询使用时间的问题
- VB 压缩Access数据库
- VB连接ACCESS数据库
- VB 压缩Access数据库
- VB操作access数据库
- VB连接access数据库
- VB中查询SQL数据库中的表内容
- VB 查询SQL SERVER数据库内容源码 工程下载
- 在vb中利用按钮把access查询内容导入到excel 002
- VB操作ACCESS数据库代码
- vb连接Access数据库自定义
- vb.net 链接Access数据库
- VB.NET压缩ACCESS数据库
- vb.net 连接 access 数据库
- VB.NET操作Access数据库
- vb.net连接数据库 Access
- VB中,连接ACCESS数据库
- Android Studio系列教程1一--下载与安装
- linux vi选中文本方法
- android build 过程 (ramdisk.img、sytem.img、userdata.img)和 启动过程简单分析
- 杨氏矩阵第K小值/两个数组元素之和最小值
- Remove Nth Node From End of List
- VB查询ACCESS数据库内容
- Ubuntu下使用SQLCipher命令行对db加密
- HTMLParser半自动解析网页的应用
- 在linux上部署Java项目
- Gaming鼠标术语解析
- Linux里如何查找文件内容
- String s 与String s1 = new String();的本质区别及==与equals的区别。
- android listvieew PullToRefreshListView设置setOnTouchListener()失效
- Selenium 元素定位