尝试:
Sub Button3_Click()
Dim conn As New ADODB.Connection
With Sheets("Sheet1")
conn.Open "Provider=SQLNCLI11;Server=myServer;Database=myDatabase;Trusted_Connection=yes;"
iRowNo = 6
Do Until .Cells(iRowNo, 1) = ""
dtDateTime = .Cells(iRowNo, 1)
sTag = .Cells(iRowNo, 10)
If sTag <> "" Then
conn.Execute "insert into RawData(oDateTime,oTag) values ('" & dtDateTime & "', '" & sTag & "')"
End If
iRowNo = iRowNo + 1
Application.StatusBar = "Processing..."
Loop
MsgBox "Upload success!", vbInformation, "AOA"
Sheet1.Range("A6", "L100000").ClearContents
Sheet1.Cells(6, 1).Select
conn.Close
Set conn = Nothing
End With
End Sub