ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

vba¨Ï¥ÎADO±NEXCEL¸ê®Æ¾É¤J¨ìSQL Server

vba¨Ï¥ÎADO±NEXCEL¸ê®Æ¾É¤J¨ìSQL Server

Sub test()
    Dim cn As ADODB.Connection
    Dim strSQL As String
    Dim lngRecsAff As Long
    Set cn = New ADODB.Connection
    cn.Open "Provider=SQLOLEDB;Data Source=xxx;" & _
        "Initial Catalog=Mydata;User ID=sa;Password=54123"

       'Import by using OPENROWSET and SELECT query.
    strSQL = "SELECT * INTO Newtable FROM " & _
        "OPENROWSET('Microsoft.ACE.OLEDB.12.0', " & _
        "'Excel 12.0;Database=C:\Users\My\Desktop\222.xlsx', " & _
        "[Sheet1$])"
    Debug.Print strSQL
    cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
    Debug.Print "Records affected: " & lngRecsAff

    cn.Close
    Set cn = Nothing
End Sub
Wrong.png

¨Ï¥Îsql server³sµ²¦øªA¾¹Excellink
Select * From Openquery(Excellink,'Select * from [sheet1$]')
¥i¥H¥¿½T¾É¤JExcel¼Æ¾Ú¨ìSql Server

µM¦Ó¥ÎVBA ADO¾É¤J ´N·|³ø¿ù,½Ð°Ý¬O§_¬OÅv­­°ÝÃD?

        ÀR«ä¦Û¦b : ¥¬¬I¦p¼½ºØ¡A¥HÅw³ß¤ß´þ¼íºØ¤l¡A¤~·|µoªÞ¡C
ªð¦^¦Cªí ¤W¤@¥DÃD