我是VB6的新手,我在MSChart.columnlabel中遇到问题,我将从数据库中检索数据,我的产品表中有名称字段。问题是每当我运行程序时,会弹出一个msgbox
"在与所请求的名称或序号相对应的集合中找不到该项。"请帮我。谢谢
我在这里发布我的代码:
Private cn As ADODB.Connection
Private rsProducts As ADODB.Recordset
Private Sub Form_Load()
Set cn = New ADODB.Connection
MSChart1.ToDefaults
Const ConnectionString = "MySQL ODBC 5.1 Driver; SERVER=10.237.2.152; DATABASE=monitoring;UID=root;PWD=c0k3float;DSN=itemearv;"
' Open the connection.
cn.Open ConnectionString
Dim strQuery As String ' SQL query string.
' Create a query that retrieves only four fields.
'strQuery = "SELECT ProductName, UnitPrice,
'UnitsInStock, UnitsOnOrder FROM Products"
strQuery = "Select value from test.product"
Set rsProducts = New ADODB.Recordset
' Open the recordset.
rsProducts.CursorLocation = adUseClient
rsProducts.Open strQuery, cn, adOpenKeyset
' Set the DataSource to the recordset.
With MSChart1
.ShowLegend = True
Set .DataSource = rsProducts
.ColumnCount = rsProducts.RecordCount
.RowCount = 1
.RowLabel = "TESTING"
End With
Dim i As Integer
i = 1
While i <= rsProducts.RecordCount
With MSChart1
.Column = i
.Row = 1
.Data = rsProducts!Value
.ColumnLabel = rsProducts!Name
End With
rsProducts.MoveNext
i = i + 1
Wend
Set rsProducts = Nothing
End Sub
答案 0 :(得分:2)
更改select
命令以包含Name
:
strQuery = "Select value,Name from test.product"