代码如下:
FileName = "2011-11"
If Form2.Command1 Then
sj1 = Format(Form2.DTPicker3, "hh:nn:ss")
sj2 = Format(Form2.DTPicker5, "hh:nn:ss")
Else
sj1 = "00:00:00"
sj2 = Format(Now, "hh:nn:ss")
End If
chaxun1 = " Select " & CXL & " From 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # order by 时间"
YZ1 = chaxun1
XZ = " Select 时间 From 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # order by 时间"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\" & FileName & ".mdb;Persist Security Info=False"
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\" & FileName & ".mdb;Persist Security Info=False"
Adodc1.RecordSource = YZ1
Adodc2.RecordSource = XZ
Adodc1.Refresh
Adodc2.Refresh
Ma = " select max(" & CXL & ") from 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # "
Mi = " select min(" & CXL & ") from 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # "
ts = " select count(*) from 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # "
ymax1 = sql_result(Ma)
ymin1 = sql_result(Mi)
zl = sql_result(ts)
模块:
Public Function sql_result(sql As String) As String
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = CreateObject("adodb.connection")
conn.Provider = "Provider=Microsoft.Jet.OLEDB.4.0"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\" & FileName & ".mdb;Persist Security Info=False"
rs.Open sql, conn, adOpenStatic, adLockOptimistic
conn.Execute (sql)
sql_result = rs(0).Value
conn.Close
End Function
首先是执行后rs.value这里使用无效null,其次之前试过后zl得不到时间范围内记录条数,zl=0.请各位帮忙看看,谢谢了。
FileName = "2011-11"
If Form2.Command1 Then
sj1 = Format(Form2.DTPicker3, "hh:nn:ss")
sj2 = Format(Form2.DTPicker5, "hh:nn:ss")
Else
sj1 = "00:00:00"
sj2 = Format(Now, "hh:nn:ss")
End If
chaxun1 = " Select " & CXL & " From 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # order by 时间"
YZ1 = chaxun1
XZ = " Select 时间 From 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # order by 时间"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\" & FileName & ".mdb;Persist Security Info=False"
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\" & FileName & ".mdb;Persist Security Info=False"
Adodc1.RecordSource = YZ1
Adodc2.RecordSource = XZ
Adodc1.Refresh
Adodc2.Refresh
Ma = " select max(" & CXL & ") from 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # "
Mi = " select min(" & CXL & ") from 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # "
ts = " select count(*) from 振动量 Where 时间 Between # " & Form2.DTPicker1.Value & " " & sj1 & " # And # " & Form2.DTPicker2.Value & " " & sj2 & " # "
ymax1 = sql_result(Ma)
ymin1 = sql_result(Mi)
zl = sql_result(ts)
模块:
Public Function sql_result(sql As String) As String
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = CreateObject("adodb.connection")
conn.Provider = "Provider=Microsoft.Jet.OLEDB.4.0"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\" & FileName & ".mdb;Persist Security Info=False"
rs.Open sql, conn, adOpenStatic, adLockOptimistic
conn.Execute (sql)
sql_result = rs(0).Value
conn.Close
End Function
首先是执行后rs.value这里使用无效null,其次之前试过后zl得不到时间范围内记录条数,zl=0.请各位帮忙看看,谢谢了。
解决方案 »
- checkbox
- 我使用以下方法来列出EXCEL中的表名到Combo1中,表名是列出来了,但是Command4_Click过程中没有关闭EXCEL,进程中每操作一次就会多一个EXCEL
- 把MSHFlexGrid中的内容导如到EXCEL,怎么在EXCEL中加入字段名
- 怎么实现窗体的拖放??
- vb里做软件最多支持多少个串口。怎样判断串口
- 关于VB中用createobject启动Excel97时,宏不被自动执行的问题,送100分,急急急急!
- vb编程数据库方面的麻烦,。。。
- VB与数据库连接问题。在线等待
- 有人知道四川苍溪地震的情况吗?
- 致firing_Sky关于(请高手指点如何做出像IE5之类风格的菜单和工具栏?)的又一回复问题
- 集自定义报表,公式,超级编辑框于一身的表格控件
- vb6.0 updown控制text问题
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set conn = CreateObject("adodb.connection")
conn.Provider = "Provider=Microsoft.Jet.OLEDB.4.0"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB\" & FileName & ".mdb;Persist Security Info=False"
rs.Open sql, conn, adOpenStatic, adLockOptimistic
'conn.Execute (sql) '不需要此句'必须对执行结果进行判断
if rs.recordcount>0 then
if not isnull(rs(0)) then
sql_result = rs(0)
end if
end if
conn.Close
End Function另外,前述的" # "在井号前后加有空格,是否会影响执行条件,没有测试,将其前后空格去掉试试看
Ma = "select max(" & CXL & ") from 振动量 Where 时间 Between #" & Form2.DTPicker1.Value & " " & sj1 & "# And #" & Form2.DTPicker2.Value & " " & sj2 & "#"
if not isnull(rs(0).value) then
sql_result = rs(0).Value
end if