工作簿1.rar
(19.87 KB, 下载次数: 4)
最近接触到数据库,
希望把EXCEL表中有A2:Q3插入到“KKKK”数据库中的表“aaa”表中,(数据库测试已经通了) 求代码,请老师出手。代码只会如下。 Dim StartTime As Variant, conn As Object, rs As Object, Mydata As String, SQL As String
'定义变量
StartTime = Timer
Mydata = "" '指定数据库名称为271模型
Set conn = CreateObject("ADODB.Connection") '建立ADODB连接对象
conn.ConnectionString = "Driver={sql server};" _
& "server=192.168.0.10;" _
& "uid=sa;pwd=123;" _
& "database=kkkk;" _
& "AutoTranslate= False"
'连接的服务器名称:WISE-THINK,所连接的数据库:271模型
conn.Open '打开连接SQL server
If conn.State = adStateOpen Then
MsgBox "数据库" & Mydata & "存在", vbInformation
Else
MsgBox "数据库" & Mydata & "不存在", vbCritical
End If '关闭记录集及数据库连接,并释放变量 conn.Close
Set conn = Nothing
MsgBox Timer - StartTime
End Sub
|