【问题标题】:Need to execute SQL query in AutoIt需要在 AutoIt 中执行 SQL 查询
【发布时间】:2017-12-02 20:49:09
【问题描述】:

我想在 AutoIt 中进行数据库操作。我为它写了一些代码,但它不起作用:

Global $adCN

$adCN = ObjCreate ("ADODB.Connection") ; <== Create SQL connection
$adCN.Open ("DRIVER={SQL Server};SERVER=sqlstaging;DATABASE=NivioAsia2;uid=niviodbstaging;pwd=niviodbstaging;") ; <== Connect with required credentials

if @error Then
    MsgBox(0, "ERROR", "Failed to connect to the database")
    Exit
Else
    MsgBox(0, "Success!", "Connection to database successful!")
EndIf

$sQuery = "select * from irws_m_users where n_userid=10318583224314"

$adCN.Execute($sQuery)

$adCN.Close ; ==> Close the database

Exit

如何使用AutoIt从表中获取数据?

【问题讨论】:

    标签: sql-server autoit


    【解决方案1】:

    现在已经完成了……

    $constrim="DRIVER={SQL Server};SERVER=sqlstaging;DATABASE=NivioAsia2;uid=niviodbstaging;pwd=niviodbstaging;"
    $adCN = ObjCreate ("ADODB.Connection") ; <== Create SQL connection
    $adCN.Open ($constrim) ; <== Connect with required credentials
    MsgBox(0,"",$constrim )
    
    if @error Then
        MsgBox(0, "ERROR", "Failed to connect to the database")
        Exit
    Else
        MsgBox(0, "Success!", "Connection to database successful!")
    EndIf
    
    $sQuery = "select * from irws_m_users where n_userid=10318583224314"
    
    $result = $adCN.Execute($sQuery)
    MsgBox(0, "", $result.Fields( "s_username" ).Value)
    $adCN.Close ; ==> Close the database
    

    【讨论】:

    • 我只是复制并粘贴了这段代码,没有更改任何值,我在 AutoIt 中收到消息“连接到数据库成功!”。怎么会?
    • @maniootek 问题是 if 之前的 MessageBox。每个函数调用都会清除@error,并且由于MessageBox 成功,@error 为0。
    猜你喜欢
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-06
    • 1970-01-01
    • 1970-01-01
    • 2022-01-06
    相关资源
    最近更新 更多