| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 555 人关注过本帖
标题:查询不了两个时间段的数据
只看楼主 加入收藏
huluting
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-1-13
收藏
 问题点数:0 回复次数:0 
查询不了两个时间段的数据

今天我写了一段程序,是关于时间段数据的查询显示的,可是我怎么调试都达不到目的,我的程序如下:
Option Explicit
Private Values() As Variant
Private NumPoints As Integer

Private Sub LoadData()
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim dbname As String
Dim i As Integer
Dim dbfilename As String
Dim ConnectString As String
Dim apppath As String


' 打开数据库
Dim strsql As String
Set db = New ADODB.Connection
If Right(App.Path, 1) = "\" Then
apppath = App.Path
Else
apppath = App.Path & "\"
End If
dbfilename = apppath & "data.mdb"
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
dbfilename & ";Persist Security Info=False;"

On Error Resume Next
With db
.CursorLocation = adUseClient
.Open ConnectString
End With
' 获得数据库记录

Set rs = New ADODB.Recordset
rs.Open "SELECT date, 流量 FROM bysj", db, 2, 3


' 查看数据库中记录数

strsql = "select * from bysj where date between " & "#" & Textmindate.Text & "# and #" & Textmaxdate.Text & "#"
NumPoints = rs.RecordCount
ReDim Values(1 To NumPoints, 1 To 2)

' 加载数据
rs.MoveFirst

For i = 1 To NumPoints
Values(i, 1) = rs!Date
Values(i, 2) = rs!流量
rs.MoveNext
Next i

rs.Close
db.Close
End Sub
Private Sub Form_Load()
With MSChart1
.Top = 0
.Left = 0
.Width = Me.ScaleWidth
.Height = Me.ScaleHeight
End With

' 读取数据
LoadData

End Sub
Private Sub Comexit_Click()
Unload Me
End Sub

Private Sub Command1_Click()
If CDate(Textmaxdate.Text) < CDate(Textmindate.Text) Then
MsgBox "后面的日期应大于前面的!" + Chr(13) + "为了选出您想要的记录请修改过来.", 48, "日期错误"
Textmaxdate.SelStart = 0
Textmaxdate.SelLength = 8
Textmaxdate.SetFocus
Else
Adodc1.RecordSource = "select * from bysj where date between " & "#" & Textmindate.Text & "# and #" & Textmaxdate.Text & "#"
Adodc1.Refresh
' 使用MSChart控件显示数据
MSChart1.ChartData = Values
MSChart1.chartType = VtChChartType2dLine
MSChart1.Visible = True
End If
End Sub

Private Sub Textmaxdate_LostFocus()
If Not IsDate(Textmaxdate.Text) Then
Textmaxdate.SelStart = 0
Textmaxdate.SelLength = 8
Textmaxdate.SetFocus

End If
End Sub
Private Sub Textmindate_LostFocus()
If Not IsDate(Textmindate.Text) Then
Textmindate.SelStart = 0
Textmindate.SelLength = 8
Textmindate.SetFocus
End If
End Sub
我调了很久,不过在MSCHART上显示的是数据库里面的全部数据,还怎么改呢?

搜索更多相关主题的帖子: 时间段 数据 查询 
2006-04-04 22:45
快速回复:查询不了两个时间段的数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016531 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved