如何在AutoIT上加载文件并将其导入数据库?

时间:2019-06-24 11:48:24

标签: autoit

我无法选择文件并在AutoIT上加载到数据库。

AutoIT,MS SQL,Windows 7

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0,"", "SQL check")
            If ProcessExists("SQLAGENT.EXE") Then
                MsgBox(0,"", "Ok")
                MsgBox(0,Choose File", "File")
        Else
            MsgBox(0, "", "SQL not running!")
        EndIf
        $ConnObj="DRIVER={SQL Server};SERVER=test;uid=sa;pwd=***;"
        $adCN = ObjCreate("ADODB.Connection")
        $adCN.Open($ConnObj)
        $message = "ChooseFile."
        $MyDocsFolder = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}"
        $var = FileOpenDialog($message, @DocumentsCommonDir & "\", "All files(*.*)")
        If @error Then
            MsgBox(4096, "", "OK.")
        Else
            MsgBox(4096, "", "You choose " & $var)
            $verify = MsgBox(4, "OK", "Load: Yes or No?  ")
        If $verify = 6 Then
            MsgBox(0, "", "Load file")
            $sqlCon = ObjCreate("ADODB.Connection")
            $sqlCon.Open("Provider=SQLOLEDB; Data Source=test; uid=sa;Password=***;")
            $sqlCon.Execute("CREATE DATABASE test_11")
            Exit
          EndIf
        EndIf
    EndSwitch
WEnd

“我希望您可以编写如何选择导入和加载文件的方法”

1 个答案:

答案 0 :(得分:0)

在AutoIt中:

您应该将FileRead() / FileWrite()FileOpen()和$ FO_BINARY参数一起使用。

通过这种方式,您将使用“ BinaryVariant”数据类型,也称为“ BLOB”

在SQL中:

您应该在SQL中使用SELECT和INSERT来将“ BLOB”读/写到SQL数据库。