關(guān)于ADO記錄集設計解決方案
學習ADO時,你可能會遇到ADO記錄集問題,這里將介紹ADO記錄集問題的解決方法,在這里拿出來和大家分享一下。根據(jù)您決定使用哪一種上述解決方案,可以有幾種不同的方法來實現(xiàn)這一點。我們將單獨考察每個解決方案。返回的數(shù)據(jù)是記錄集的一種簡單XML數(shù)據(jù)表示?,F(xiàn)在,我們將使用MicrosoftXMLDocumentObjectModel(DOM)來檢索此數(shù)據(jù),以便在內(nèi)部循環(huán)處理每一條記錄,XML對這一過程的表示如下:
- PrivateSubCommand1_Click()
- DimaryArtists()AsString
- DimoRopeasNewRope.Proxy
- oRope.LoadServicesDescriptionicURI,"http://MyServer/GetArtists.xml"
- GetArtistsFromXMLoRope.GetAllArtists(),aryArtists()
- '現(xiàn)在aryArtists()是包含我們的藝術(shù)家的一個數(shù)組
- SetoRope=Nothing
- EndSub
- http://www.mscto.com
- PrivateSubGetArtistsFromXML(ByValsXMLAsString,ByRefaryArtists()AsString)
- DimoXMLAsNewMSXML.DOMDocument
- DimoXMLDocumentAsMSXML.IXMLDOMElement
- DimiCountAsInteger
- DimxAsInteger
- oXML.loadXMLsXML
- SetoXMLDocument=oXML.documentElement
- iCount=oXMLDocument.childNodes.length
- ReDimaryArtists(iCount-1)
- Forx=0ToiCount-1
- aryArtists(x)=oXMLDocument.childNodes.Item(x).Text
- Next
- SetoXML=Nothing
- SetoXMLDocument=Nothing
- EndSub
#T#Command1_Click()方法使用ROPE調(diào)用服務。因為該服務按解決方案1中指定的方式返回數(shù)據(jù),所以現(xiàn)在就可以傳遞包含在我們的XML字符串中的返回數(shù)據(jù)。我們按值傳遞該字符串,并按引用傳遞一個將被置入PublicSubGetArtistsFromXML中的空數(shù)組。此過程置入數(shù)組并將它返回給調(diào)用過程。數(shù)組變量aryArtists()現(xiàn)在包含我們的藝術(shù)家的一個數(shù)組。為了將此XML數(shù)據(jù)返回給一個ADO記錄集,我們需要將數(shù)據(jù)加載到XMLDOM中,然后使用ADO記錄集的OPEN方法創(chuàng)建藝術(shù)家的記錄集:
- PrivateSubCommand1_Click()
- DimoRSAsADODB.Recordset
- DimoRopeasNewRope.Proxy
- oRope.LoadServicesDescriptionicURI,"http://MyServer/GetArtists.xml"
- SetoRS=CreateADORSFromXML(oRope.GetAllArtists())
- '現(xiàn)在oRS是包含我們的藝術(shù)家數(shù)據(jù)的一個分離的ADO記錄集
- SetoRope=Nothing
- SetoRS=Nothing
- EndSub
- PrivateFunctionCreateADORSFromXML(ByValsXMLAsString)AsADODB.Recordset
- DimoXMLAsNewMSXML.DOMDocument
- DimoRSAsNewADODB.Recordset
- oXML.loadXMLsXML
- oRS.OpenoXML
- SetCreateADORSFromXML=oRS
- SetoRS=Nothing
- SetoXML=Nothing
- EndFunction
在Command1_Click()事件中,ROPE對象調(diào)用我們的方法,該方法會就像在解決方案2中那樣返回我們的XML字符串。通過調(diào)用CreateADORSFromXML函數(shù),就可以設置一個對象引用從SOAP返回數(shù)據(jù)創(chuàng)建一個分離的記錄集。






