vb6 或VBS执行 SQL 语句后,怎么得到返回值
TableExecuteSQL"C:\Test.mdb","select*fromTestTablewhere姓名='张三'"SubTableExecuteSQL(str...
TableExecuteSQL "C:\Test.mdb", "select * from TestTable where 姓名='张三'"
Sub TableExecuteSQL(strDBPath, strSQLCode)
Dim connObj
Set connObj = CreateObject("ADODB.Connection")
connObj.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = " & strDBPath
connObj.execute strSQLCode
End Sub
我怎么判断这个sql语句返回的真假呢,我用open老是会遇到到错误,想问问有没有别的方法 展开
Sub TableExecuteSQL(strDBPath, strSQLCode)
Dim connObj
Set connObj = CreateObject("ADODB.Connection")
connObj.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = " & strDBPath
connObj.execute strSQLCode
End Sub
我怎么判断这个sql语句返回的真假呢,我用open老是会遇到到错误,想问问有没有别的方法 展开
1个回答
展开全部
一般情况下,建议用记录集(recordset)操作,这样可以得到个记录集,如二维表.如你这代码,做插入或删除还行,用作查询不方便了.
追问
能给个代码示范下吗
追答
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "Provider = Microsoft.Jet.OLEDB.4.0; " & _
"Data Source = inventory.mdb"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM GeneralProperties", _
objConnection, adOpenStatic, adLockOptimistic
objRecordSet.MoveFirst
Do While Not objRecordSet.EOF
strComputer = objRecordSet("ComputerName")
WScript.Echo vbCrLf & strComputer
Wscript.Echo String(Len(strComputer), "-")
Set objWMIService = GetObject("winmgmts:\\" & strComputer)
Set objService = objWMIService.Get("Win32_Service.Name='W3SVC'")
WScript.Echo objService.Name, objService.State
objRecordSet.MoveNext
Loop
objRecordset.Close
objConnection.Close
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询