sql >> Database >  >> RDS >> Mysql

VBA-code om gegevens op te halen uit Mysql DB in Mac Excel 2011

Na veel googlen kwam ik deze voorbeeldcode tegen van Bryan Duchesne in MSDN:

Sub TestSqlConnection()
Dim sqlstring As String
Dim connstring As String
Dim sLogin As String
sLogon = "Uid=myUserID;Pwd=myPassowrkd;"
sqlstring = "select * from zitemloc"
connstring = "ODBC;DSN=myDSN;" & sLogon
ActiveSheet.Range("B1:t2000").Clear

Dim qt As QueryTable
For Each qt In ActiveSheet.QueryTables
    qt.Delete
Next qt
With ActiveSheet.QueryTables.Add(Connection:=connstring, Destination:=Range("B1"),   Sql:=sqlstring)
    .BackgroundQuery = False
    .Refresh
End With

Set qt = ActiveSheet.QueryTables(1)
Dim rowCount As Integer
rowCount = UBound(qt.ResultRange.Value)


Dim ix, iy As Integer
Dim data As Variant
Dim colCount As Integer
colCount = qt.ResultRange.Columns.Count

For ix = 1 To rowCount
    If Not IsArray(data) Then
            ReDim data(rowCount - 1, colCount - 1)
    End If
    For iy = 1 To qt.ResultRange.Columns.Count
        data(ix - 1, iy - 1) = qt.ResultRange.Value2(ix, iy)

    Next
Next
End Sub



  1. php artisan migreerfout:nodename noch servname opgegeven of niet bekend

  2. eenvoudige sql-query, resultaten combineren en delen

  3. Vreemd gedrag met mysql_affected_rows() in PHP

  4. PARSE() vs TRY_PARSE() in SQL Server:wat is het verschil?