Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
123
返回列表 发新帖
楼主: maokind

菜鸟提问:如何动态获取SQL SERVER输出行数用于图表?

[复制链接]
 楼主| 发表于 2011-4-12 16:11 | 显示全部楼层
下面这段程序有问题吗? 我按命令按钮后,提示下标越界的错误。前两天运行还没问题的啊

Dim conn As New ADODB.Connection
Dim sql As String
Dim rs As ADODB.Recordset
Private Sub CommandButton1_Click()   '2éÑˉTCX Cell for test
'Set conn = CreateObject("adodb.connection")
'conn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;hdr=yes';data source=" & ThisWorkbook.Path & "\dbku.xls"
conn.Open "rovider=SQLOLEDB.1;Data Source=logic-E5400;Initial Catalog=TCX_20101208;User ID=saassword=sgmw5050ersist Security Info=False;"
sql = "select ix1.item_id Product_SN,ix1.component_item_id BASE_QR,ix2.component_item_id BOOSTER_QR,ph2.VAL_1 as BASEWELD_Volts,ph3.VAL_3-ph3.VAL_1,ph1.VAL_3 Resistance from process_history ph1,item i, item_xref ix1,item_xref ix2,process_history ph2,process_history ph3 where ph1.item_id=i.item_id and i.operation_id=999 and i.item_type='SERIALIZED' and i.item_id not like '%TCX%' and ph1.item_id=ix1.item_id and ix1.component_item_id not like '1T%'and ix1.component_item_id=ix2.item_id and ix2.component_item_id not like '1T%' and ph2.source_id='C-CT4'  and  ph2.item_id=ix1.component_item_id and ph1.source_id='C-CT15'and ph3.source_id='C-CT5' and ph3.item_id=ix2.component_item_id and ph1.time_stamp>'2010-12-01 09:17:18.497'"
ThisWorkbook.Sheets(8).Cells(3, 1).CopyFromRecordset conn.Execute(sql) '

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
回复

使用道具 举报

 楼主| 发表于 2011-4-12 16:16 | 显示全部楼层
回复 兰色幻想 的帖子

最关键的问题还是 希望能系列的行数能根据实际查询结果的行数变化
回复

使用道具 举报

发表于 2011-4-12 16:17 | 显示全部楼层
本帖最后由 兰色幻想 于 2011-4-12 16:19 编辑
maokind 发表于 2011-4-12 16:16
回复 兰色幻想 的帖子

最关键的问题还是 希望能系列的行数能根据实际查询结果的行数变化


我给你设置的就是可以变的。你别从数源那里看,从系列那里看。
未命名.jpg
回复

使用道具 举报

发表于 2011-4-12 16:19 | 显示全部楼层
下标越界 是对象不存在或数组元素不存在的提示
回复

使用道具 举报

 楼主| 发表于 2011-4-12 16:23 | 显示全部楼层
兰色幻想 发表于 2011-4-12 16:17
我给你设置的就是可以变的。你别从数源那里看,从系列那里看。

弱弱的一问,2007如进入系列画面?
回复

使用道具 举报

发表于 2011-4-12 16:28 | 显示全部楼层
网吧电脑上只有2003,没法帮你找了,你自已找找看
回复

使用道具 举报

 楼主| 发表于 2011-4-12 16:40 | 显示全部楼层
网吧?版主你太强了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-8 10:04 , Processed in 0.233853 second(s), 8 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表