2011-09-14 56 views
1

AutoItでデータベース操作を行いたいです。私はそれのためにいくつかのコードを書いて、それが動作していない:AutoItでSQLクエリを実行する必要があります

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を使用してテーブルからデータを取得することができますか?

それは今行われています

答えて

3

...

$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 
+1

私はちょうどコピーして任意の値を変更せずにこのコードを貼り付け、私はAutoItの中で、「データベースへの接続に成功する!」というメッセージを受け取りました。どうして? – maniootek

+1

@maniootek問題はifより前の 'MessageBox'です。すべての関数呼び出しは '@ error'をクリアし、MessageBoxが成功するので@errorは0になります。 –

関連する問題