Supplementary perspective: Convert the DataSet returned by ADO.NET or WebService to AdoDb.Recordset

zhaozj2021-02-17  61

Supplementary perspective: Convert the DataSet returned by ADO.NET or WebService to AdoDb.Recordset

Small gas god 2001-10-23

I remember that in the article "Perspective and Adjusting Your Enterprise and Business System", we discussed some questions about components, soap, webservice, especially for such problems:

How to generate a simple three-layer structure (Window DNA)

How to expose existing components to become a WebService

How to use MS SOAP Toolkit to generate Client Consumer WebService

How to call SOAP Toolkit to generate WebService in DOTNET

How to deal with and transmit the data of the AdoDb.Recordset type, implement your own CTM.

How to encapsulate current components into WebService

In some discussion and experiments, when discussing our components into WebService with ASP.NET, then use MS SOAP Toolkit Consumption WebService, I have skipped a problem, which is how to receive the group data transferred over WebService.

Remember that the code is like this:

DIM RETXML ​​AS Object

Dim SoapClient as mssoaplib.soapclient

SET SOAPCLIENT = New MSSOAPLIB.SOAPClient

Call SoapClient.msoapinit ("http://dereksvr/authors/authors.asmx? WSDL")

Set retXML = soapclient.getauthors ()

GetAuthors () returns a DataSet type, we are packaged when starting to generate WebService:

Public Function GetAuthors () AS Dataset

DIM OBJ AS bus_authors.authors

DIM RST As Adodb.Recordset

Dim mydataadapter as oledb.oledbdataadapter

Dim RetdataSet As DataSet

Obj = new bus_authors.authors ()

RST = new adodb.recordset ()

MyDataAdapter = new oledb.oledbdataadapter ()

RetDataSet = new dataset ()

RST = Obj.GetAuthors ()

MyDataAdapter.Fill (RetDataSet, RST, "GetAuthors")

GetAuthors = RetDataSet

END FUNCTION

For VB RETXML, it will not be able to know and directly, so that DataSet is based on XML, in fact it is regular, we can access .asmx files directly (http: // dereksvr / authors / authors .asmx) to call this webservice's getAuthors () on the web page, we can see this DataSet structure in IE so we can find the law to use the data in this Dataset.

According to the above situation I wrote a function to convert DataSet to AdoDb.Recordset

Public Function ConvdataSettorecordSet (Byval Vonl as IxmldomNodeList, Byval vstablename As String) as adoDb.recordsetdim ixmltablenode as ixmldomnode

DIM IXmlRecordNode as ixmldomnode

DIM IXMLFIELDNODE As IXmldomnode

Dim Ixmlnodelist as ixmldomnodelist

DIM RETRS As Adodb.Recordset

DIM SXPATH AS STRING

ON Error Goto Errhandle

'Create Recordset Using The Xsd Schema

SXPATH = "// xsd: element [@ name =" "& vStablename &" "] / xsd: complexType / xsd: sequence"

Set ixmltablenode = Vonl.Item (1) .selectsinglenode (SXPATH)

SET RETRS = New AdoDb.Recordset

For each ixmlfieldnode in ixmltablenode.childNodes

If not ixmlfieldnode.attributes is nothing then

Call retrs.fields.append (ixmlfieldnode.attributes (0) .text, getDataType (IXMLFIELDNODE.ATITRIBUTES (1) .text), 512)

END IF

NEXT

'Add the data to the recordset

SXPATH = "//" & vStablename

Set ixmlnodelist = Vonl.Item (3) .selectnodes (SXPATH)

Call retrs.open

For each ixmlrecordnode in ixmlnodelist

Call Retrs.AddNew

For each ixmlfieldnode in ixmlrecordnode.childNodes

IXMLFIELDNODE.BASENAME> 0 THEN

Retrs.fields (ixmlfieldnode.basename) = IXMLFIELDNODE.TEXT

END IF

NEXT

NEXT

IF NOT (RETRS.BOF AND RETRS.EOF) THEN CALL RETRS.MOVEFIRST

Set convdatasettorecordset = retrs

Errexit:

EXIT FUNCTION

Errhandle:

Set convodatasettorecordset = Nothing

Resume errexit

END FUNCTION

Private function getDataType (byval vStype as string) as adodb.datatypeenum

'Convert the xsd datatype to a

ADO

DataType

Select Case vStype

Case "XSD: String"

GetDataType = advarchar

Case "XSD: INT"

GetDataType = Adinteger

Case "XSD: DateTime"

GetDataType = addatecase "xsd: decimal"

GetDataType = addouble

Case "XSD: Boolean"

GetDataType = Adboolean

End SELECT

END FUNCTION

I don't have one by one in GetDataType, only a few common, specific can see the link below:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmrefsupportedDataTypeConversions.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdcstDataTyPeenum.asp

Continue to add to ensure that you can meet your specific needs. Then set the function of our performance layer in the third article in a GRID:

Set retXML = soapclient.getauthors ()

Set result = convodatasettorecordset (Retxml, "GetAuthors")

Lvwheadname Lstauthors, Strheaders

AdOfilllvw Result, Lstauthors

Think about it is very interesting, starting to be adoDb.recordset type, then convert to a DataSet type in WebService, and then convert to AdoDb.Recordset. XML is a powerful medium, while the Dataset will be a breakthrough than the Recordset from the previous version. The application of DataSet will also be extremely flexible and unlimited because its core and foundation is XML.

Since it is a supplement, I should also request the project and code of the example involved in the perspective and adjustment. The other is a copy screen, I hope that the two will have a little help for reading and understanding, the specific installation process I will omit. Related Documents: http://263.9cbs.net/filebbs/files/2001_10/t_724_1.zip(CODE) http://263.9cbs.net/filebbs/files/2001_10/t_724_2.zip(JPG)

especially:

The above text and pictures involve other people's privacy and personal rights, such as non-authorized or agree, please do not publish, reprint, adapt, repost, or other forms of communication. All of the above texts and images are only used for internal communication, and do not make any news publishers and commercial purposes.

转载请注明原文地址:https://www.9cbs.com/read-31023.html

New Post(0)