怎樣用excelVBA將sql數(shù)據(jù)庫中數(shù)據(jù)的列名讀?
Sub 按鈕1_Click()
Dim i As Integer, j As Integer, sht As Worksheet 'i,j為整數(shù)變量;sht 為excel工作表對象變量,指向某一工作表
'Dim cn As New ADODB.Connection '定義數(shù)據(jù)鏈接對象 ,保存連接數(shù)據(jù)庫信息;請先添加ADO引用
'Dim rs As New ADODB.Recordset '定義記錄集對象,保存數(shù)據(jù)表
‘工具 ---〉引用 ---〉Microsoft ActiveX data objects ....
'下面兩句就不需要增加引用ADO
Set cn = CreateObject("Adodb.Connection")
Set rs = CreateObject("Adodb.Recordset")
Dim strCn As String, strSQL As String '字符串變量
Dim strCond As String
strCn = "Provider=sqloledb;Server=R9HDET7;Database=dbname;Uid=username;Pwd=password" '定義數(shù)據(jù)庫鏈接字符串