SELECT * FROM data where format(now(),"yyyymmddhh") = format(dt,"yyyymmddhh")
1.一个简单的查询的例子:'*定义一个连接
Dim Conn As ADODB.Connection
'*定义一个记录集
Dim mrc As ADODB.Recordset
'*分别实例化
Set Conn = New ADODB.Connection
set mrc =New ADODB.Recordset
'*定义一个连接字符串
dim ConnectString as string
ConnectString="provider=microsoft.jet.oledb.4.0data source=" &App.Path &"\data\数据库名.mdbjet oledb:database password=数据库密码"
'*打开连接
Conn1.Open ConnectString
'*定义游标位置
Conn1.CursorLocation = adUseClient
'*查询记录集(从student表中找出名子为"张三"的记录)
mrc.open "select * from student where name='张三'",Conn, adOpenKeyset, adLockOptimistic
'*现在你已经得到了你想要查询的记录集了,那就是mrc
'*你可以把此记录集与DataGrid榜定,用datagrid显示你查询的记录
set me.datagrid.datasource=mrc
多条件混合模糊搜索"select * from 表名 where 字段名 Like'%" &text1.text &"%'and 字段名 like'%" &combo1.text &"%' and 字段名 like'%" &text2.text &"%'"
例子
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strsql As String
Dim cnstr As String
Private Sub Form_Load() '窗口打开时,连接数据库
conn.CursorLocation = adUseClient
cnstr = "Provider=Microsoft.Jet.OLEDB.4.0Data Source= db1.mdbJet OLEDB:Database Password=" '修改成你的数据为地址/密码
conn.ConnectionString = cnstr
conn.Open cnstr
End Sub
Private Sub Command1_Click()
if rs.state=adstateopen then rs.close'记录集打开时则关闭记录集
strsql ="select * from 表名 where 字段名 Like'%" &text1.text &"%'and 字段名 like'%" &combo1.text &"%' and 字段名 like'%" &text2.text &"%'"
rs.Open strsql, conn, 3, 3
set DataGrid1.DataSource =rs
'这时适当调整一下datagird控件的格式(略)
End Sub
Private sub form_unload()
conn.close
end sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)