找回密码
 加入
搜索
查看: 2768|回复: 5

同志们,帮我看看,au3变量写入数据库语句怎么写?

[复制链接]
发表于 2009-9-11 20:29:17 | 显示全部楼层 |阅读模式
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#NoTrayIcon
$mdb_data_path="au3.mdb"
$mdb_data_pwd=""
$tblname="COMPUTER"

;获得本机地址与MAC
Runwait(@comspec & " /c ipconfig /all > c:\connect.txt","",@sw_hide)
$file1 = FileOpen("c:\connect.txt", 0)
$len = StringLen("        Physical Address. . . . . . . . . : ")
While 1
$line = FileReadLine($file1)
If @error = -1 Then ExitLoop
If StringLeft($line,$len) = "        Physical Address. . . . . . . . . : " then
  $mymac = StringMid($line,$len + 1)
endif
Wend
FileClose($file1)
FileDelete("c:\connect.txt")

;~ 框架部分

Opt('GUICloseOnESC', 0)


GUICreate ("EDP",310,375)
$ccc=GUICtrlCreateButton("退出",220,340,80,25)
$Save=GUICtrlCreateButton("保存配置",130,340,80,25)
$close=GUICtrlCreateLabel("提示:固定资产盘点",10,340,110,25)
GUICtrlCreateLabel("描述",10,10,60,25)
GUICtrlSetColor(-1,0x000000)
$regcomputername1 = RegRead( "HKLM\SYSTEM\ControlSet001\Services\lanmanserver\parameters", "srvcomment" )
$computername1=GUICtrlCreateInput($regcomputername1 ,50,10,250,20)

GUICtrlCreateLabel("名称",10,30,60,30)
GUICtrlSetColor(-1,0x000000)
$regcomputername = RegRead( "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName", "ComputerName" )
$computername=GUICtrlCreateInput($regcomputername ,50,30,250,20)

GUICtrlCreateLabel("帐户",10,50,60,30)
GUICtrlSetColor(-1,0x000000)
$regcomputeruser = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUserName")
$computeruser=GUICtrlCreateInput($regcomputeruser ,50,50,250,20)

GUICtrlCreateLabel("主板",10,70,60,30)
GUICtrlSetColor(-1,0x000000)
$board=GUICtrlCreateInput("",50,70,250,20)

GUICtrlCreateLabel("CPU",10,90,60,30)
GUICtrlSetColor(-1,0x000000)
$cpu=GUICtrlCreateInput("",50,90,250,20)

GUICtrlCreateLabel("显卡",10,110,60,30)
GUICtrlSetColor(-1,0x000000)
$display=GUICtrlCreateInput("",50,110,250,20)

GUICtrlCreateLabel("硬盘",10,130,60,30)
GUICtrlSetColor(-1,0x000000)
$harddisk=GUICtrlCreateInput("",50,130,250,20)

GUICtrlCreateLabel("内存",10,150,60,30)
GUICtrlSetColor(-1,0x000000)
$Memory=GUICtrlCreateInput("",50,150,250,20)

GUICtrlCreateLabel("网卡",10,170,60,30)
GUICtrlSetColor(-1,0x000000)
$network=GUICtrlCreateInput("",50,170,250,20)

GUICtrlCreateLabel("声卡",10,190,60,30)
GUICtrlSetColor(-1,0x000000)
$sound=GUICtrlCreateInput("",50,190,250,20)

GUICtrlCreateLabel("系统",10,210,60,30)
GUICtrlSetColor(-1,0x000000)
$Windows_System=GUICtrlCreateInput("",50,210,250,20)

GUICtrlCreateLabel("Bios",10,230,60,30)
GUICtrlSetColor(-1,0x000000)
$bios=GUICtrlCreateInput("",50,230,250,20)

GUICtrlCreateLabel("IP",10,250,60,30)
GUICtrlSetColor(-1,0x000000)
TCPStartup()
$IPAddress=GUICtrlCreateInput(TCPNameToIP(@ComputerName) ,50,250,250,20)

GUICtrlCreateLabel("MAC",10,270,60,30)
GUICtrlSetColor(-1,0x000000)
TCPStartup()
$mymac=GUICtrlCreateInput($mymac ,50,270,250,20)

GUICtrlCreateLabel("光驱",10,290,60,30)
GUICtrlSetColor(-1,0x000000)
$cdrom=GUICtrlCreateInput("",50,290,250,20)

GUICtrlCreateLabel("显示器",10,310,60,30)
GUICtrlSetColor(-1,0x000000)
$monitor=GUICtrlCreateInput("",50,310,250,20)
GUISetState(@SW_SHOW)

$g_szVersion = "info"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)


GUICtrlRead($computername)

info()
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
                Case $Save
                        sx()
                Case $ccc
                        Exit                
        EndSwitch
WEnd

Func info()
        
$objWMIService = objget("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
$colBios = $objWMIService.ExecQuery("Select * from Win32_BIOS")
$colBoard = $objWMIService.ExecQuery("Select * FROM Win32_BaseBoard")
$colSettings = $objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
$colMemory = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
$colCPU = $objWMIService.ExecQuery("Select * from CIM_Processor")
$colVideoinfo = $objWMIService.ExecQuery("Select * from Win32_VideoController")
$colSound = $objWMIService.ExecQuery("Select * from Win32_SoundDevice")
$colMouse = $objWMIService.ExecQuery("Select * from Win32_PointingDevice")
$colMonitor = $objWMIService.ExecQuery("Select * from Win32_DesktopMonitor")
$colNIC = $objWMIservice.ExecQuery("Select * from Win32_NetworkAdapter Where Netconnectionstatus = 2")
$colharddisk =$objwmiservice.execQuery("select * from win32_diskdrive")
$colcdrom =$objwmiservice.execQuery("select * from win32_CDROMDrive")


For $object in $colBios
        GUICtrlSetData($bios,StringMid($object.Caption,1))
                ExitLoop
Next

For $object in $colcdrom
        GUICtrlSetData($cdrom,StringMid($object.Caption,1))
                ExitLoop
Next

For $object in $colMonitor
        GUICtrlSetData($monitor,StringMid($object.Caption,1))
                ExitLoop
Next

For $object in $colBoard
        GUICtrlSetData($board,$object.Product)
        ExitLoop
Next

For $object in $colCPU
        GUICtrlSetData($cpu, StringStripWS($object.Name,1))
                ExitLoop
Next

For $object in $colVideoinfo
        GUICtrlSetData($display, StringStripWS($object.Description ,1))
        ExitLoop
Next

For $object in $colSound
        GUICtrlSetData($sound, StringStripWS($object.Description ,1))
                ExitLoop
Next

For $object in $colNIC
        GUICtrlSetData($network, StringStripWS($object.name ,1))
        ExitLoop
Next

For $objOperatingSystem in $colSettings

        GUICtrlSetData($Windows_System,$objOperatingSystem.Caption & " Build " & $objOperatingSystem.BuildNumber & " Sp " & $objOperatingSystem.ServicePackMajorVersion & "." & $objOperatingSystem.ServicePackMinorVersion )
        ExitLoop
Next

for $object  in $colMemory
        GUICtrlSetData($Memory,String(Int(Number($object.TotalPhysicalMemory) / (1024 * 1024))) & " MB")
        ExitLoop
Next

dim $all_Hard
For $object in $colHardDisk
        $all_Hard=$all_Hard & ";" & StringMid($object.Caption,1)
        Next
$all_Hard=StringMid($all_Hard,2)
GUICtrlSetData($harddisk,$all_Hard) 
EndFunc
Func sx()
         $addfld = ObjCreate("ADODB.Connection")
         $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
         $addfld.Execute("insert into COMPUTER (description,computer,username,motherboard,cpu,graphics,harddisk,memory,nic,sound,os,bios,ip,mac,dirve,monitors) values('"&$regcomputername1&"','"&$computername&"','"&$board&"','"&$cpu&"','"&$display&"','"&$harddisk&"','"&$Memory&"','"&$network$&"','"&$sound$&"','"&$Windows_System&"','"&$bios&"','"&$IPAddress&"','"&$mymac&"','"&$cdrom&"','"&$monitor&"')")
             $addfld.close
         MsgBox(4096, "提示:"," 成功写入数据库!") 
EndFunc
发表于 2009-9-11 21:45:43 | 显示全部楼层
这不是已经写好了吗?
如果上面的代码是自己写的应该知道怎么把数据写到数据库
 楼主| 发表于 2009-9-12 11:29:40 | 显示全部楼层
SQL写入语法那一段有问题,换成数字1234可以写入,但是换成变量就不行了。
相当的奇妙。诸位帮帮忙!
 $addfld.Execute("insert into COMPUTER (description,computer,username,motherboard,cpu,graphics,harddisk,memory,nic,sound,os,bios,ip,mac,dirve,monitors) values('"&$regcomputername1&"','"&$computername&"','"&$board&"','"&$cpu&"','"&$display&"','"&$harddisk&"','"&$Memory&"','"&$network$&"','"&$sound$&"','"&$Windows_System&"','"&$bios&"','"&$IPAddress&"','"&$mymac&"','"&$cdrom&"','"&$monitor&"')")
发表于 2009-9-12 15:30:39 | 显示全部楼层
values('"&$regcomputername1&"'
这里应该就有问题了,搞清‘和“的配对,原来是字符串,更改为变量,要做相应的修改
发表于 2009-9-12 15:56:17 | 显示全部楼层
values('"' & $regcomputername1 & '"'
 楼主| 发表于 2009-9-12 22:51:03 | 显示全部楼层
为什么要用两对双引号?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-22 21:35 , Processed in 0.080459 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表