循环中调用数据库函数出错
For Rrow = 2to EXCELrow + 1msgbox xlSheet.cells(2,2)
CString = "DRIVER=SQL Server;SERVER=XIONGRQ\SQL2005;UID=sa;PWD=Xiongruiqi123;APP=2007 Microsoft Office system;WSID=XIONGRQ;DATABASE=0623-QTP"
SeString = xlSheet.cells(Rrow,2)
setbbb = databaseFunction(CString,SeString)
ContractCode = bbb(0)
Browser("XXX").Page("XXX").Frame("ifrmGrid_2").WebElement("innertext:="&ContractCode,"html tag:=NOBR").Click
Browser("XXX").Page("XXX").Frame("Frame").Image("mnuDown").Click
Page("Page").WebElement("mnu_rArrow").Click'点击删除
Message = Browser("xxx").Dialog("Microsoft Internet Explorer").Static("xxx!").GetROProperty("text")
If Message = xlSheet.cells(Rrow,1) Then
Reporter.ReportEvent 0,Message+"校验","通过(不能删除)"
Browser("xxx").Dialog("Microsoft Internet Explorer").WinButton("确定").Click
else
Reporter.ReportEvent 1,Message+"校验","失败(应该不能删除)"
End If
Rrow = Rrow +1
Next
CloseExcel(XL)
function databaseFunction(ConnectString,SelectString)
Dim cmd,sql,Res
Set Res = Createobject("adodb.recordset")
Set Cmd = Createobject("adodb.command")
Cmd.activeconnection = ConnectString
Cmd.commandtype = 1
Cmd.commandtext = SelectString
Set Res = Cmd.Execute() 第二次运行的时候在这里报错
Set databaseFunction = Res
Set Res = nothing
Set Cmd.activeconnection = nothing
Set Cmd = nothing
end function
Function OpenExcel(BooksName,SheetName,XlApp)
'Stracfile = PathFinder.Locate(BooksName)
Set XlApp = CreateObject("Excel.Application")
Set XlBook = XlApp.WorkBooks.Open(BooksName)
Set xlSheet = XLbook.Worksheets(SheetName)
xlApp.Visible = False
setOpenExcel= xlSheet
End Function
Function CloseExcel(XlApp)
XlApp.Activeworkbook.save
XlApp.Quit
Set XlBook = Nothing
Set XlApp= Nothing
End Function 你看看你第二次执行循环时,从excel中取到sql语句了吗? 先释放recordset对象
页:
[1]