Home   |   Asp.Net 2.0   |   .Net Framework 2.0   |   IIS 6.0   |   Sql Server 2005   |   Visual Basic 2005   |   c# 2005   |   VS 2005   |   Visual Source Safe 2005

MS Dynamics CRM 3.0

SharePoint Portal Server 2003
SharePoint Server 2007
Dynamics NAV
Dynamics CRM
SharePoint Designer 2007
SharePoint Portal Server 2001
Windows SharePoint Services
Windows SharePoint Services 3.0
Project Server 2003
Project Server 2007
Dynamics – Point of Sale
Dynamics AX
Dynamics GP
Dynamics Retail Management System (RMS)
Dynamics SL
SQL Server 2000
Visual Basic .NET 2003
Visual C# .NET 2003
Visual C++ .NET 2003
Visual C++ 2005
Visual SourceSafe 6.0
Windows Server 2003
Windows Server 2003
Outlook 2003
ADO.NET 1.1
ASP.NET 1.0
Visual Studio Team Foundation Server
Visual Studio 2005 Team Edition
Windows Internet Explorer 7
BizTalk Server 2000
BizTalk Server 2002
BizTalk Server 2004
BizTalk Server 2006
Visual Studio 6.0
Access 2000
Access 2002
Access 2003
Access 2007
Access 97
Collaboration Data Objects 2.0
Commerce Server 2002
Content Management Server 2001
Commerce Server 2007
Content Management Server 2002
Data Access Components 2.7
Data Access Components 2.8
DirectX 9.0b
Office Small Business Accounting 2006
Accounting 2007
ActiveSync 4.1
Class Server 2.0
Groove 2007
Windows Vista
Outlook 2007
OneNote 2003
OneNote 2007
Office X for Mac
Zune software
Zune Live
Zoo Tycoon 2
Flight Simulator 2002
Dungeon Siege II

Cervo Technologies
The Right Source to Outsource

Oracle Database FAQS

Sharepoint Portal Server KB

Outlook 2007 Knowledge Base Articles

Visual Studio 6.0 Knowledge Base Articles

This article demonstrates how to programmatically retrieve an XML data stream from a SQL Server 2000 mapping schema by using an XPath query. The scope operates in a client/server (2-tier) model. This sample also allows you to test XPath queries...


For a Microsoft Visual Basic .NET version of this article, see .

SUMMARY

This article demonstrates how to programmatically retrieve an XML data stream from a SQL Server 2000 mapping schema by using an XPath query. The scope operates in a client/server (2-tier) model.

This sample also allows you to test XPath queries against the mapping schema. For each query, the text box of the form displays the XML; the elements of the XML data stream are broken onto separate lines for viewing purposes.

MORE INFORMATION

1.Create a new Visual Basic application. Form1 is created by default.
2.On the Project menu, click References, and then set a reference to Microsoft ActiveX Data Objects.
3. Create two TextBox controls, that ae named and labeled txtResults and txtXPath, respectively. Size txtXPath to the width for your form and one line in height. To display the results, size txtResults as large as possible, and then set the Multi-line property to True.
4. Create two CommandButton controls, that are named and labeled cmdTestIt, and cmdExitProgram, respectively.
5.On the code window of Form1, paste the following code:
Option Explicit

Dim gCn As New ADODB.Connection

'
' DBGUID values for the command object's dialect property
'
Const DBGUID_DEFAULT As String = "{C8B521FB-5CF3-11CE-ADE5-00AA0044773D}"
Const DBGUID_SQL As String = "{C8B522D7-5CF3-11CE-ADE5-00AA0044773D}"
Const DBGUID_MSSQLXML As String = "{5D531CB2-E6Ed-11D2-B252-00C04F681B71}"
Const DBGUID_XPATH As String = "{ec2a4293-e898-11d2-b1b7-00c04f680c56}"

Private Sub cmdExitProgram_Click()
    Unload Me
    End
End Sub

Private Sub cmdTestIt_Click()

    '   ADODB.Command used for the query
    Dim cmd As ADODB.Command
    '   ADODB.Stream used to set up the command to execute
    Dim strm As ADODB.Stream

    On Error GoTo trap
    '   create a new ADODB.Command
    Set cmd = New ADODB.Command
    '   establish connect for the command object to the database
    Set cmd.ActiveConnection = gCn

    '   create the ADODB.Stream for the results.
    Set strm = New ADODB.Stream
    '   open the result stream so it may receive the output from the execute
    strm.Open
    '   set the command type to an XPath query
    cmd.Dialect = DBGUID_XPATH

    '   set the file name for the mapping schema
    cmd.Properties("Mapping Schema") = App.Path & "\CustomerOrder.xdr"
    '   hook up the command to the result stream
    cmd.Properties("Output Stream") = strm
    '   trim off any additional space 

    txtXPath = Trim(txtXPath)
    If txtXPath = "" Then
        '   no search path default to customers. (CasE SeNsiTiVe)....
        txtXPath = "Customers"
    End If

    '   set the actual text for the XPath command
    cmd.CommandText = txtXPath

    '   execute the command stream
    cmd.Execute , , adExecuteStream

    '   reset the stream's position in order to read it 
    strm.Position = 0

    '   set the displayed results to the command's output
    txtResults = strm.ReadText

    '   clean up the output to make easier to read 
    txtResults = Replace(txtResults, "><", ">" & vbCrLf & "<")

   '   reset the stream's position in order to read it
    strm.Position = 0

    strm.Close

GoTo cleanup

trap:

    ' report errors 
    MsgBox "Error (" & Err.Number & ") -- " & Err.Description

cleanup:
    '   clean up 
    Set strm = Nothing
    Set cmd = Nothing

    Exit Sub

End Sub

Private Sub Form_Load()

On Error GoTo trap
    Set gCn = New ADODB.Connection
    gCn.ConnectionString = "PROVIDER=SQLOLEDB;Data Source=.;Initial Catalog=Northwind;uid=sa;pwd="
    gCn.Open
    Exit Sub

trap:
    MsgBox "Failed to connect to database.  Program Shutting down."
    Unload Me
    End

End Sub
					
6.Create the mapping schema against which the XPath queries. Either place the file into the project folder (app.path), or fully qualify the path to the file where the Mapping Schema property is set. Save as CustomerOrder.xdr.
<?xml version="1.0" ?>

<Schema xmlns="urn:schemas-microsoft-com:xml-data"
        xmlns:dt="urn:schemas-microsoft-com:datatypes"
        xmlns:sql="urn:schemas-microsoft-com:xml-sql">

    <ElementType name="CustOrder" sql:relation="Orders">
        <AttributeType name = "CustomerID" />
        <AttributeType name = "OrderID" />
        <AttributeType name = "OrderDate" />
        <AttributeType name = "ShipCity" />

        <attribute type = "CustomerID"  sql:field="CustomerID" />
        <attribute type = "OrderID"     sql:field="OrderID" />
        <attribute type = "OrderDate"   sql:field="OrderDate" />
        <attribute type = "ShipCity"    sql:field="ShipCity" />

    </ElementType>

    <ElementType name="Customers" sql:relation="Customers">

        <AttributeType name = "CustomerID" />
        <AttributeType name = "CompanyName" />
        <AttributeType name = "ContactName" />
        
        <attribute type = "CustomerID"   sql:field="CustomerID" />
        <attribute type = "CompanyName"  sql:field="CompanyName" />
        <attribute type = "ContactName"  sql:field="ContactName" />
        
        <element type="CustOrder" >
            <sql:relationship key-relation="Customers"
                           key="CustomerID"
                           foreign-key="CustomerID"
                           foreign-relation="Orders"  />
        </element>
        
    </ElementType>
    
</Schema>
					
7. Save the mapping schema and run the sample. To test the query, you can enter the following XPath queries into the txtXPath textbox. (The default is set to Customers.)
    Customers
    Customers[@CustomerID]
    Customers[@CustomerID='ALFKI']
    Customers/CustOrder[@CustomerID='ALFKI']
					

REFERENCES

For SQL Server 2000, please see SQL Server Books Online.

For XML, see the MSDN page on the following Microsoft Web site:
http://www.msdn.microsoft.com/xml/default.asp (http://www.msdn.microsoft.com/xml/default.asp)


APPLIES TO
Microsoft SQL Server 2000 Standard Edition
Microsoft Data Access Components 2.6
Microsoft Data Access Components 2.7
Microsoft Visual Basic 6.0 Professional Edition
Microsoft Visual Basic 6.0 Enterprise Edition
Microsoft XML Parser 2.6
Microsoft XML Core Services 4.0
Microsoft XML Core Services 4.0

Keywords: 
kbhowto KB271619

Copyright © 2004 - 2007 Gridview.org, Inc. All rights reserved. Powered by Smart Web Content Management System