Toon posts:

MS ACCES import sql file

Pagina: 1
Acties:

Verwijderd

Topicstarter
He dudios,

Ik heb een mysql database en die heb ik geexporteerd naar een sql file. Die sql file wil ik importen in een acces database. Wil allemaal niet echt lukken. Ik kan niet eens vinden of het uberhaupt wel kan(importeren sql file). Weet iemand of dat kan? Heb wel gezocht her en der maar kon niks bruikbaars vinden. Thanx.

  • PhoeniX-
  • Registratie: Juni 2000
  • Laatst online: 29-04 09:11
Geen idee eigenlijk!

Via ODBC kan je ook je MySQL DB benaderen .. misschien is dat een idee?

Verwijderd

je kan de mysqltabellen rechtstreeks in access linken mbv. de myodbc driver

  • Boss
  • Registratie: September 1999
  • Nu online

Boss

+1 Overgewaardeerd

Ik heb daar ook nog wel een keer wat code voor gemaakt in een module. Code zonder garantie en zie maar wat je ermee doet. CreateSQL leest de SQL die nodig is om de juiste tabellen te maken. InsertSQL leest de SQL en parsed de INSERT statements.

Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Private Function CreateSQL() As String
Dim fsObject As Scripting.FileSystemObject
Dim fsFile As Scripting.TextStream
Dim strLine As String
Dim strSQL As Variant

    Set fsObject = CreateObject("Scripting.FileSystemObject")
    Set fsFile = fsObject.OpenTextFile("C:\tbdump.txt", ForReading, False)

    Do While Not fsFile.AtEndOfStream
        strLine = fsFile.ReadLine
        If Left(strLine, 12) = "CREATE TABLE" Then
            Do While Not strLine = ");"
                strSQL = strSQL & strLine
                strLine = fsFile.ReadLine
            Loop
        End If
    Loop
    strSQL = Replace(strSQL, Chr(34), "")
    strSQL = Replace(strSQL, "DEFAULT '' ", "")
    strSQL = Replace(strSQL, "TEXT", "MEMO")
    strSQL = Replace(strSQL, "VARCHAR", "CHAR")
    strSQL = Replace(strSQL, "   ", " ")
    strSQL = Replace(strSQL, "NOT NULL", "")
    Open "C:\test.txt" For Output As #1
    Write #1, strSQL
    Close #1
    DoCmd.RunSQL strSQL & ");"
    fsFile.Close

End Function


Private Function InsertSQL() As String
Dim fsObject As Scripting.FileSystemObject
Dim fsFile As Scripting.TextStream
Dim strLine As String
Dim strSQL As Variant

    Set fsObject = CreateObject("Scripting.FileSystemObject")
    Set fsFile = fsObject.OpenTextFile("C:\tbdump.txt", ForReading, False)

    strLine = fsFile.ReadLine
    Do While Not Left(strLine, 11) = "INSERT INTO"
        strLine = fsFile.ReadLine
    Loop
    
    If Left(strLine, 11) = "INSERT INTO" Then
        Do While Left(strLine, 11) = "INSERT INTO"
            strSQL = strLine
            Do While Not Right(strLine, 2) = ");"
                strLine = fsFile.ReadLine
                strSQL = strSQL & vbNewLine & strLine
            Loop
            strSQL = Replace(strSQL, Chr(34), "")
            strSQL = Replace(strSQL, "\'", "`")
            strSQL = Replace(strSQL, "'\`", "'\'")
            DoCmd.RunSQL strSQL
            If fsFile.AtEndOfStream Then Exit Do
            strLine = fsFile.ReadLine
        Loop
    Else
        MsgBox "end?", vbOKOnly
    End If
    
    fsFile.Close

End Function

The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it is an aesthetic experience much like composing poetry or music.