"Calling the database via MSChart control" in VB6.0
The MSChart control in VB6.0 is a powerful advanced chart tool with a wealth of chart drawing features that show two-dimensional and three-dimensional rods, regional diagrams, line graphs, pie charts, etc. Recently, in order to display the contents of the database corresponding to the area in the DataGrid control in order to double-click a certain area of the chart, there is a lot of difficulties, and finally use a custom variable SelectSeries to solve the problem, the specific method is as follows:
Set up the database name "Student Information", there is an Access table "Student Results", its content is a class of students' test scores, including students, name, grades, 3 fields, grade field formats, value "excellent" One of "Good", "Medium", "Poor".
Form1 includes a MSChart control McScore, a two-dimensional cake diagram for displaying each grade, an ADO control ADSCore is used to connect to a database; a DataGrid control DGSCore is used to display database content in a table.
The work process is: Double-click on a certain area of the pie chart, then DGScore shows the list of studentists.
code show as below:
Option expedition
DIM SELECTEDSERIES AS INTEGER 'Custom Variable
DIM RS () AS String 'Extracts Record Comsetted Characters
Private sub flow_load ()
'Set the data source of the DataGrid control
Dgscore.DataSource = "adscore"
'Set the connection string of the ADO control and the initial record source, that is, display content
Adscore.connectString = "provider = microsoft.Oledb.3.51; persist_security info = false; data source = student information
ADSCORE.Recordsource = "SELET * FROM student grades ORDER BY grades"
ADSCORE.REFRESH
'Preset SQL statement for extracting records
RS (1) = "SELECT * FROM Student Score Where Results =" CHR (34) "Excellent" _chr (34) "Order By Grade"
RS (2) = "SELECT * FROM student grades where scores =" CHR (34) "good" _chr (34) "ORDER BY grade"
RS (3) = "SELECT * FROM student grades where scores =" CHR (34) "中" _chr (34) "Order By grade"
RS (4) = "SELECT * FROM student grades WHERE grades =" chr (34) "difference" _chr (34) "Order By grade"
End Sub
Private sub mcscore_seriesselected (Series as ", mouseflags as _integer, cancel as integer
SELECTEDSERIES = Series
End Sub
Private sub mcscore_pointselected (Series As INTEGER, DATAPOINT AS_INTEGER, MOUSEFLAGS AS
Integer, Cancel AS Integer
SELECTEDSERIES = Series
End Sub
Private sub mcscore_db1click ()
'Change the record source of the ADO control and refresh adoc1.recordsource = rs (seletedseries)
Adoc1.refresh
End Sub