Dim itemData,result
'将返回的数据集对象赋值给result
Set result = QueryDatabase(tablename,fieldname1,fieldname2,fieldname3,network)
'下面如何将result中的每行数据依次打印出来?
'被调用程序
public Function QueryDatabase(byref tablename,byref fieldname1,byref fieldname2,byref fieldname3,byref network)
On error resume next
Dim cnn,objrsa,sql
Set cnn=createobject("adodb.connection")
Set objrsa=createobject("adodb.recordset")
cnn.open "rovider=OraOLEDB.Oracle.1assword=***ersist Security Info=True;User ID=***;Data Source=database"
If cnn.State=0 then
cnn.close
Set cnn=nothing
Call WriteMsg(logFileNow,"连接数据库失败")
Else
Call WriteMsg(logFileNow,"连接数据库成功")
End If
'执行查询语句
sql="select "&fieldname1&","&fieldname2&" from "&tablename&" where "&fieldname3&" like '%"&network&"'"
objrsa.open sql ,cnn,3,2
'将结果集对象返回调用者
Set QueryDatabase = objrsa
If err<>0 Then
cnn.close
Set cnn=nothing
Call WriteMsg(logFileNow,"获得数据库数据时发生异常")
End If
cnn.close
Set cnn=nothing
End Function