执行SQL命令调用au3变量问题(附源程序)
#include <Process.au3>#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <mysql.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 366, 155, 486, 269)
$Label1 = GUICtrlCreateLabel("号码:", 64, 40, 52, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 112, 40, 193, 21)
$Button1 = GUICtrlCreateButton("查 询", 112, 104, 43, 25)
$Button2 = GUICtrlCreateButton("退 出", 224, 104, 51, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
Select
Case $nmsg = $Button1
If FileExists("C:\cx.txt") Then
FileDelete("C:\cx.txt")
endif
$passlen=StringLen(GUICtrlRead($Input1))
if $passlen<12then
MsgBox(16, "错误", "输入的号码位数不正确,请重新输入!")
ContinueLoop
endif
$conn = ObjCreate("ADODB.Connection")
$RS = ObjCreate("ADODB.Recordset")
$conn.Open ("driver={SQL Server};server=127.0.0.1;uid=XXX;pwd=XXX;database=XXX")
$RS.ActiveConnection = $conn
$conn.Execute("EXEC master..xp_cmdshell 'bcp ""select kh from .. where kh=GUICtrlRead($Input1)
"" queryout c:\cx.txt -c -Slocalhost -Uxxx -Pxxx'");这句错误,不知道怎么回事 $file = FileOpen("c:\cx.txt", 0)
If $file = -1 Then
MsgBox(0, "错误", "不能打开文件!")
Exit
endif
$line = FileReadLine($file)
MsgBox(4096, "结果",GUICtrlRead($Input1))
If $line<>GUICtrlRead($Input1) Then
MsgBox(0, "警告:", "输入的号码不存在,请重新输入。。。")
else
MsgBox(4096, "结果", "查询成功!")
endif
Case $nmsg = $Button2
exit
EndSelect
WEnd
为什么在执行“$conn.Execute("EXEC master..xp_cmdshell 'bcp ""select kh from .. where kh=GUICtrlRead($Input1)
"" queryout c:\cx.txt -c -Slocalhost -Uxxx -Pxxx'")
”这句的时候不能生成"c:\cx.txt"呢?还有其它的办法直接可以得用au3命令在SQL数据库里面查询吗?不用生成结果,比如执行SQL命令后,直接检测返回参数就可以了。 期待高手出现... 本帖最后由 tubaba 于 2011-7-17 14:58 编辑
这句根本就通不过编译吧,看看你影号用的对不对,把你在sql查询分析器里能通过运行的代码放上来看看
$conn.Execute("EXEC master..xp_cmdshell 'bcp ""select kh from .. where kh=GUICtrlRead($Input1)"" queryout c:\cx.txt -c -Slocalhost -Uxxx -Pxxx'")
where kh=GUICtrlRead($Input1) 光是这个,就不对,GUICtrlRead($Input1)是个变量,
如果 kh是int类型,那么写成 "where kh=" & GUICtrlRead($Input1)
如果是字符型那么写成 "where kh='" & GUICtrlRead($Input1) & "'"
页:
[1]