mschart+ADO 代码。不知道哪里错了。
运行后提示变量未定义,错误指向:ConnectionString程序是为了实现从数据库查找符合条件的记录,并把记录条数赋予变量sex1和sex2。
然后在mschart中用饼图画出统计图。
Option Explicit
Private Values(1, 1) As Variant
Dim Sex1 As Integer
Dim Sex2 As Integer
' 载入数据
Private Sub LoadData()
Values(0, 0) = "男"
Values(0, 1) = Sex1
Values(1, 0) = "女"
Values(1, 1) = Sex2
End Sub
Private Sub Command1_Click()
With MSChart1
.Top = 0
.Left = 0
.Width = Me.ScaleWidth
.Height = Me.ScaleHeight
End With
' 读取数据
LoadData
' 使用MSChart控件显示数据
MSChart1.ChartData = Values
End Sub
Private Sub Form_Load()
Dim Scan As String
Dim Scan2 As String
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Scan = "男"
Scan2 = "女"
rs.CursorLocation = adUseClient ' 这里不懂
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\sAnKes\Desktop\data.mdb;Persist Security Info=False" '
cn.Open ConnectionString
rs.Open "select * from 预约者 where 性别 = '" & Scan & "'", cn, adOpenKeyset, adLockOptimistic
Sex1 = rs.RecordCount
rs.Close
rs.Open "select * from 预约者 where 性别 = '" & Scan2 & "'", cn, adOpenKeyset, adLockOptimistic
Sex2 = rs.RecordCount
End Sub