sql-server - 试图将 MS SQL Server 表中的值放入 Excel VBA 中的表单中的列表框
问题描述
我正在尝试以表单的形式显示 ListBox 中的表中的数据,但没有成功。以下是我正在使用的代码:
Dim cnt As ADODB.Connection
Dim rst As ADODB.Recordset
Dim stDB As String, stConn As String, stSQL As String
Dim xlCalc As XlCalculation
Dim vaData As Variant
Dim k As Long
Dim cs As String
Set cnt = New ADODB.Connection
cs = "DRIVER=SQL Server;"
cs = cs & "DATABASE=dbname;"
cs = cs & "SERVER=."
cnt.ConnectionString = cs
stSQL = "SELECT * from table"
With cnt
.CursorLocation = adUseClient
.Open stConn
Set rst = .Execute(stSQL)
End With
With rst
Set .ActiveConnection = Nothing
vaData = .GetRows
End With
cnt.Close
ListBoxReqJobs.Value = vaData
'this is the part I need help with.
Set rst = Nothing
Set cnt = Nothing
End Sub
关于如何正确显示数据的任何建议?我似乎无法格式化数据以正确显示行,并且大约有 5-6 列。
解决方案
推荐阅读
- eigen3 - Eigen::Map 构造函数抱怨“不是常量表达式”
- webpack - 应用程序未使用 webpack AOT 为 prd 构建 nativescript
- postgresql - 如何在 postgresql 中使用 postgres_fdw 从另一个数据库中获取记录
- java - 如何通过不继承Activity的类打开屏幕
- c - 是否可以在此代码中使用重复结构?
- mongodb - 自动更新集合中的所有文档。如果其中一个在交易过程中发生变化怎么办?
- javascript - 我能够将数据从 Spring 引导控制器传递到 html 页面,但是如何访问 Java Script 中的数据?
- swift - 如何在 Swift ui 底部使用 ScrollView 启动视图?
- delphi - 您可以将 AddEventListener 与 CEF4Delphi 一起使用吗?
- sql - 在 Oracle SQL 中查询不返回单行时更新