- Dim MacAddr
-
- Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
- Set colItems = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled='TRUE'")
- For Each objItem In colItems
- NetName = Replace(objItem.Description,"/","_")
- MacAddr = objItem.MacAddress
- Next
- Set colItems = Nothing
-
- sql = """"&"select MacAddress From speed where macaddress = '" & Macaddr &"'"&""""
- Set cn=WScript.CreateObject("ADODB.Connection")
- Set rs=WScript.CreateObject("adodb.recordset")
- cn.open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=\\win-pc\meno\vbs\ceshi.mdb"
- rs.CursorLocation = 3
-
- rs.open sql,cn,1,3
- If Not rs.EOF Then
- MsgBox "有"
- Else
- MsgBox "没有"
- End If
复制代码 我想获取本机的mac地址,再与数据库中的macaddress字段查找一下是否已经有记录了。
但是脚本在这一句出现问题了。- sql = """"&"select MacAddress From speed where macaddress = '" & Macaddr &"'"&""""
复制代码 在这里改为使用变量后就运行出错。
错误提示:
脚本: z:\3.vbs
行:: 17
字符: 1
错误: 无效的SQL语句;期待'''DELETE、'INSERT'、'PROCEDURE'、'SELECT'、或'UPDATE'
代码: 80040E14
源: Microsoft JET Database Engine
而我将变量取消调试的时候:- sql = "select MacAddress From speed where macaddress = '00-0C-29-50-37-D3'"
复制代码 这样又是正确的。
小弟初学,实在没辙,试过了好多方法,都没办法解决。特此诚心向各位高手、好汉、英雄们讨教应该如果加入变量? |