怎样用excelVBA将sql数据库中数据的列名读
1个回答
展开全部
Sub 按钮1_Click()
Dim i As Integer, j As Integer, sht As Worksheet 'i,j为整数变量;sht 为excel工作表对象变量,指向某一工作表
'Dim cn As New ADODB.Connection '定义数据链接对象 ,保存连接数据库信息;请先添加ADO引用
'Dim rs As New ADODB.Recordset '定义记录集对象,保存数据表
‘工具 ---〉引用 ---〉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" '定义数据库链接字符串
Dim i As Integer, j As Integer, sht As Worksheet 'i,j为整数变量;sht 为excel工作表对象变量,指向某一工作表
'Dim cn As New ADODB.Connection '定义数据链接对象 ,保存连接数据库信息;请先添加ADO引用
'Dim rs As New ADODB.Recordset '定义记录集对象,保存数据表
‘工具 ---〉引用 ---〉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" '定义数据库链接字符串
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询