以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 XML 与 数据库 』 (http://bbs.xml.org.cn/list.asp?boardid=17) ---- [求助]谁会SQL数据库转成XML格式的文档 (http://bbs.xml.org.cn/dispbbs.asp?boardid=17&rootid=&id=18720) |
-- 作者:playboylinlin -- 发布时间:5/23/2005 4:26:00 PM -- [求助]谁会SQL数据库转成XML格式的文档 本人现在急需把SQL数据库的东西转成XML格式的文档,这样的一个工具的源代码,那位大哥或大姐,会的话帮小弟编一个 ,语言没有限制,只要有这个功能.先谢谢各位了 本人QQ:9472398 |
-- 作者:canxing -- 发布时间:5/25/2005 9:42:00 AM -- 我也想要了…… |
-- 作者:keeponline -- 发布时间:6/11/2005 12:51:00 PM -- 我也想要 |
-- 作者:jx27 -- 发布时间:6/17/2005 6:50:00 PM -- 呵呵,得用PHP。 没编过,不好意思,帮不到你 |
-- 作者:webdev -- 发布时间:6/27/2005 1:08:00 PM -- 自己写个啊,取得表的字段名和字段值,然后封装就行了,不过外围的标签你还是需要自己定义的。 |
-- 作者:315zxl -- 发布时间:8/5/2005 4:25:00 PM -- 自己写一个呀!! |
-- 作者:xcccb -- 发布时间:9/5/2005 6:46:00 PM -- 用asp.net来写: sqlcommand.commandText="select * from employee for xml auto,xmldata" sqlcommand.commandType = CommandType.Text dim xmlReader as xml.xmlTextReader xmlReader = sqlcommand.executexmlreader dataset.readxml(xmlreader,xmlreadmode.fragment) dim filename as filestream = new filestream("test.xml",filemode.create) ds.writexml("test.xml") |
-- 作者:弄清影 -- 发布时间:9/23/2005 1:34:00 PM -- 首先建立与数据库的连接,本例子用SQL Server中的Northwind数据库中的Supplier表,为Supplier表创建存储过程命名为GetSupplierXml seleclt............ for xml auto 用.net平台C# 语言 namespace SupplierListDB //调用存储过程String strQuery = "GetSupplierList"; OleDbConnection objConnect = new OleDbConnection(m_ConnectString); // get the data into a table named "Suppliers" in the DataSet // declare a String containing the stored procedure name // 打开连接 // declare a String containing the stored procedure name // method to return an XmlDocument object containing // declare a String containing the stored procedure name // create a new Connection object using connection string // create new DataAdapter using stored proc name and Connection // create a new DataSet object to hold the results try // get the data into a table named "Suppliers" in the DataSet // create a new XmlDataDocument object based on the DataSet // return it an XmlDocument object to the calling routine // method to return an XML document (as a String) containing // declare a String containing the SQL-XML stored proc to execute // create a new Connection object using connection string // create new Command using stored proc name and Connection // create a variable to hold an XmlTextReader object String strXml = String.Empty; // open connection to the database // execute the stored proc to initialize the XmlTextReader // create the document prolog // read the first result row and ) read remainder // add the document epilog // method to return an Array containing the full // declare a String containing the stored procedure name // create a new Connection object using connection string // create new Command using stored proc name and Connection // create a variable to hold a DataReader object try // open connection to the database // execute query to initialize DataReader object // get the index of the last column within the data // declare a variable to hold the result array int intRowCount = 0; // to hold number of rows returned // iterate through rows by calling Read method until false // store column values strings in result array // increment number of rows found } objReader = null; // finished with DataReader // set Ref parameter value for number of rows in Array return arrValues; // and return array to the calling routine // method to return an ArrayList containing just the // declare a String containing the stored procedure name // create a new Connection object using connection string // create new Command using stored proc name and Connection // create a variable to hold a DataReader object try // open connection to the database // execute query to initialize DataReader object // create a new ArrayList object // iterate through rows by calling Read method until false objReader = null; // finished with DataReader return arrValues; // return ArrayList to the calling routine } |
-- 作者:弄清影 -- 发布时间:9/23/2005 1:38:00 PM -- 不好意思,上次代码有冗余, 用.net平台C# 语言 首先创建SupplierListDB数据访问组件如下: using System; using System.Collections; using System.Data; using System.Data.OleDb; using System.Data.SqlClient; using System.Xml; namespace SupplierListDB //调用存储过程String strQuery = "GetSupplierList"; OleDbConnection objConnect = new OleDbConnection(m_ConnectString); // get the data into a table named "Suppliers" in the DataSet // declare a String containing the SQL-XML stored proc to execute // create a new Connection object using connection string // create new Command using stored proc name and Connection // create a variable to hold an XmlTextReader object String strXml = String.Empty; // open connection to the database // execute the stored proc to initialize the XmlTextReader // create the document prolog // read the first result row and ) read remainder // add the document epilog <!------------------ HTML page content ---------------------> <html> <div class="heading">Supplier List : XML Document from Relational Database</div> <div align="right" class="cite"> <asp:Label id="lblMessage" runat="server" /> <!-- #include file="../global/foot.inc" --> <!-------------- server-side script section ----------------> <script Language="C#" runat="server"> void Page_Load() { // get connection string from web.config try { // create an instance of the data access component // call the method to return the data as an Xml String and // specify path to XSLT stylesheet that transforms XML for display // there was an error and no data will be returned
|
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
12,062.500ms |