从数据库db2将数据拉入excel [英] pull data into excel from database db2
本文介绍了从数据库db2将数据拉入excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试在excel宏中使用select查询。 rs.fields.count返回select查询中的列数。其实我需要表中的行数。
记录计数值也是-1。但是当在db2中执行相同的查询时,它工作正常。
例如:
trying to use select query in excel macros. rs.fields.count returns the count of columns in the select query. Actually i need the count of rows in the table.
also recordcount value is -1. however when the same query is excuted in db2, it works fine.
Eg:
sql = "select a,b,c from tblname where d = 100;"
Set cmdobj = New ADODB.Command
cmdobj.ActiveConnection = varcnn
cmdobj.CommandText = sql
Set rs = cmdobj.Execute(sql)
For i = 0 To rs.Fields.Count - 1
Sheet2.Cells(r, i + 1) = rs.Fields(i).Value
Sheet2.Cells(r, i + 1).Interior.ColorIndex = 36
Sheet2.Cells(r, i + 1).Borders.Value = 1
Next i
提前感谢
thanks in advance
推荐答案
从基础开始:
在Microsoft上使用ADO Visual Basic [ ^ ]
在Visual Basic 6应用程序中引用ADO库 [ ^ ]
查看我过去的答案:
ADODB连接到网站中存储的Excel文件 [ ^ ]
任何人都可以建议如何编写一个宏为此...... [ ^ ]
Start with basics:
Using ADO with Microsoft Visual Basic[^]
Referencing the ADO Libraries In a Visual Basic 6 Application[^]
See my past answers too:
ADODB Connection to a Excel File Stored in a Website[^]
Can any one suggest how to write a macro for this...[^]
这篇关于从数据库db2将数据拉入excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文