|
编写函数QueryDatabase把数据(两个字段,N行数据)从数据库中放到一个对象objrsa中,然后将objrsa返回给Action,那么,在ACTION中如何依次取出objrsa中每个数据呢?
程序如下:
Action:
Dim itemData,result
Set result = QueryDatabase(tablename,fieldname1,fieldname2,fieldname3,network)
...'往下该怎么能才取出每个字段的每一行数据呢?试了好多方法都不管啊。。
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=xxxersist Security Info=True;User ID=xxx;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
[ 本帖最后由 centurystone 于 2008-8-28 16:24 编辑 ] |
|