How to export excel data in Sql Server using ADODB Connection in VBA

Описание к видео How to export excel data in Sql Server using ADODB Connection in VBA

Please find the below mentioned code:

Sub ExportExcelinSQLServer()

'Microsoft active x data object library

Dim SQLconn As New ADODB.Connection
Dim SQLrs As New Recordset
Dim r As Integer
Dim c As Integer
Dim connstr As String

connstr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=.;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=DESKTOP-OR4TSI3;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=ExcelDataBase"

SQLconn.Open connstr

SQLrs.Open "ExcelTable", connstr, adOpenDynamic, adLockOptimistic

For r = 2 To Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
SQLrs.AddNew
For c = 0 To SQLrs.Fields.Count - 1
SQLrs.Fields(c).Value = Sheet1.Cells(r, c + 1).Value

Next c
SQLrs.Update
Next r
End Sub

Комментарии

Информация по комментариям в разработке