今天我写了一段程序,是关于时间段数据的查询显示的,可是我怎么调试都达不到目的,我的程序如下:
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上显示的是数据库里面的全部数据,还怎么改呢?