首先通过ado。net将数据放在dataset中,然后调用dataset的writexml方法就行了

解决方案 »

  1.   

    EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors for xml auto" queryout c:\DT.txt -c -Sdaliserver -Usa -Pelement'
      

  2.   

    你可以用
    SELECT au_fname, au_lname FROM pubs..authors for xml auto
    SELECT au_fname, au_lname FROM pubs..authors for xml auto,elements
    ...买本书看吧,内容太多了
      

  3.   

    EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors for xml auto" queryout c:\DT.txt -c -S数据库服务器 -Usa -P密码'
      

  4.   

    我用的是asp.
    谢谢各位大侠的指导。小妹去虚心学习了。
    有问题还请大家多多指点。再多问一句。有没有已经成功的先例呀。
      

  5.   

    1.you should install SQLXML3.0
    2.IN SQL SERVER2K YOU CAN SEE  sp_xml_preparedocument/sp_xml_removedocument.
    3.SQLXML3.0 HAVE A LOT OF EXAMPLE.
    FOR EXAMPLE:
    Option Explicit
    Sub main()
    Dim oTestStream As New ADODB.Stream
    Dim oTestConnection As New ADODB.Connection
    Dim oTestCommand As New ADODB.Command
    oTestConnection.Open "provider=SQLXMLOLEDB.3.0;data provider=SQLOLEDB;data source=(local);initial catalog=Northwind;user id=UserName;password=UserPassword;"
    oTestCommand.ActiveConnection = oTestConnection
    oTestCommand.Properties("ClientSideXML") = "True"
    oTestCommand.CommandText = _
            "<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql' >" & _
           " <sql:query> " & _
            "   SELECT FirstName, LastName FROM Employees FOR XML AUTO " & _
            "   </sql:query> " & _
            " </ROOT> "
    oTestStream.Open
    ' You need the dialect if you are executing a template.
    oTestCommand.Dialect = "{5d531cb2-e6ed-11d2-b252-00c04f681b71}"
    oTestCommand.Properties("Output Stream").Value = oTestStream
    oTestCommand.Properties("Base Path").Value = "c:\Schemas\SQLXMLWR2\New Folder\ExecuteTemplateWithXSL\"
    oTestCommand.Properties("xsl").Value = "myxsl.xsl"
    oTestCommand.Execute , , adExecuteStreamoTestStream.Position = 0
    oTestStream.Charset = "utf-8"
    Debug.Print oTestStream.ReadText(adReadAll)
    End Sub
    Sub Form_Load()
     main
    End SubThe XSL template follows. The result of applying this XSL template is a two-column table.<?xml version='1.0' encoding='UTF-8'?>          
     <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
                                              
        <xsl:template match = 'Employees'>
           <TR>
             <TD><xsl:value-of select = '@FirstName' /></TD>
             <TD><B><xsl:value-of select = '@LastName' /></B></TD>
           </TR>
        </xsl:template>
        <xsl:template match = '/'>
          <HTML>
            <HEAD>
               <STYLE>th { background-color: #CCCCCC }</STYLE>
            </HEAD>
            <BODY>
             <TABLE border='1' style='width:300;'>
               <TR><TH colspan='2'>Employees</TH></TR>
               <TR><TH >First name</TH><TH>Last name</TH></TR>
               <xsl:apply-templates select = 'ROOT' />
             </TABLE>
            </BODY>
          </HTML>
        </xsl:template>
    </xsl:stylesheet>