偿试多次无果,MSChart控件怎么与数据库中的表进行连接呀,苦恼!?

liuwangxin 2004-11-01 01:30:11
我用了下面的语句,请高手指点错误,谢谢!!!
Dim conn As New ADODB.Connection
Dim strdsn As String
Dim strsql As String
Dim i As Integer
For i = 0 To 3
Form9.ado1.Recordset.AddNew
Form9.ado1.Recordset.Fields("日期时间") = Form3.moday.Value
Form9.ado1.Recordset.Fields("值别") = Form8.Label2(i).Caption
Form9.ado1.Recordset.Fields("名次") = Form8.Text1(8 + 9 * i).Text
Form9.ado1.Recordset.Update
recs = recs + 1
Next i
strdsn = "dsn=ks"
conn.Open strdsn
strsql = "select * from mici"
Set rs = conn.Execute(strsql)
With Form9.MSChart1
.ShowLegend = True
Set .DataSource = rs
End With
Form9.Show
程序执行时提示:“对象变量或with块变量未设置“,不知如何改正错误?
...全文
138 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuwangxin 2004-11-08
  • 打赏
  • 举报
回复
能否有人再次看看我代码,错在哪??
我也是用ADO控件将MSchart与access库中表连接,但就是无法显示MSchart控件,不知为何??
谢谢能帮我!!我用下面的语句:
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strdsn As String
Dim strsql As String
Dim n As Integer
Dim i As Integer
For i = 0 To 3
Form9.ado1.Recordset.AddNew
Form9.ado1.Recordset.Fields("日期时间") = Form3.moday.Value
Form9.ado1.Recordset.Fields("值别") = Form8.Label2(i).Caption
Form9.ado1.Recordset.Fields("名次") = Form8.Text1(8 + 9 * i).Text
Form9.ado1.Recordset.Update
n = n + 1
Next i
strdsn = "dsn=ks"
conn.Open strdsn
strsql = "select * from mici"
Set rs = conn.Execute(strsql)
With Form9.MSChart1
.ShowLegend = True
Set .DataSource = rs
End With
liuwangxin 2004-11-07
  • 打赏
  • 举报
回复
谢谢你,guxizhw(失落的彩虹),但我按你的做后:
Set .DataSource = Form9.ado1.Recordset 则可以连接 
Set .DataSource = rs 则不能连接,为何!
若我要选择指定字段,那不就连不上了吗?感谢你有空指点!
guxizhw 2004-11-07
  • 打赏
  • 举报
回复
'Set rs = conn.Execute(strsql)
With Form9.MSChart1
.ShowLegend = True
Set .DataSource = Form9.ado1.Recordset
End With

试试

另外你rs没有定义嘛
dim rs as new adodb.recorderset
再试试?
ylwangbin 2004-11-04
  • 打赏
  • 举报
回复
' 添加对mschart的引用
Private Sub Form_Load()
MSChart1.Plot.Axis(VtChAxisIdY).AxisTitle.Text = "人数"
MSChart1.Plot.Axis(VtChAxisIdX).AxisTitle.Text = "年度"
For i = 1999 To 2001
MSChart1.ColumnCount = 2001 - 1999 + 1
MSChart1.Column = i - 1998
MSChart1.ColumnLabel = i & "年"

MSChart1.RowCount = 2001 - 1999 + 1
MSChart1.Row = i - 1998
MSChart1.RowLabelCount = 2
MSChart1.RowLabelIndex = 1
MSChart1.RowLabel = i & "年"
MSChart1.RowLabelIndex = 2
MSChart1.RowLabel = 6 * i & "人"

MSChart1.DataGrid.SetData i - 1998, 1, 1 * i, 0
MSChart1.DataGrid.SetData i - 1998, 2, 2 * i, 0
MSChart1.DataGrid.SetData i - 1998, 3, 3 * i, 0

MSChart1.Plot.SeriesCollection.Item(1).DataPoints.Item(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
MSChart1.Plot.SeriesCollection.Item(2).DataPoints.Item(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
MSChart1.Plot.SeriesCollection.Item(3).DataPoints.Item(-1).DataPointLabel.LocationType = VtChLabelLocationTypeAbovePoint
Next i
End Sub

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧