新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> Oracle, SQL Server与XML,XML在数据挖掘中的应用, PMML.
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - 高级XML应用『 XML 与 数据库 』 → 帮忙啊,没办法了!xml与sql 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 23614 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 帮忙啊,没办法了!xml与sql 举报  打印  推荐  IE收藏夹 
       本主题类别: XML文档存取技术(DOM, SAX)    
     omeili 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:62
      门派:XML.ORG.CN
      注册:2005/3/7

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给omeili发送一个短消息 把omeili加入好友 查看omeili的个人资料 搜索omeili在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看omeili的博客楼主
    发贴心情 帮忙啊,没办法了!xml与sql

    想从sql从导出xml文件,使用VISUAL .NET2003编写的代码,不知道错在哪里了!代码测试无法通过,数据库已建立,并且在查询工具中可以正常查询。
    请教各位高手哪个地方需要修改?
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using MSXML2;
    using ADODB;

    namespace example_8._1
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
      private System.Windows.Forms.TextBox textBox1;
      private System.Windows.Forms.Button button1;
      private System.Windows.Forms.Button button2;
      ADODB._Connection pConn;
            ADODB._Recordset pRS;
      String pSelStr;
      String pUser;
      String pPSW;
      String sname;
      String dbname;
      IXMLDOMDocument xmlDoc;
      /// <summary>
      /// 必需的设计器变量。
      /// </summary>
      private System.ComponentModel.Container components = null;

      public Form1()
      {
       //
       // Windows 窗体设计器支持所必需的
       //
       InitializeComponent();

       //
       // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
       //
      }

      /// <summary>
      /// 清理所有正在使用的资源。
      /// </summary>
      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if (components != null)
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );
      }

      #region Windows 窗体设计器生成的代码
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {
       this.textBox1 = new System.Windows.Forms.TextBox();
       this.button1 = new System.Windows.Forms.Button();
       this.button2 = new System.Windows.Forms.Button();
       this.SuspendLayout();
       //
       // textBox1
       //
       this.textBox1.Location = new System.Drawing.Point(128, 48);
       this.textBox1.Multiline = true;
       this.textBox1.Name = "textBox1";
       this.textBox1.Size = new System.Drawing.Size(296, 208);
       this.textBox1.TabIndex = 0;
       this.textBox1.Text = "";
       //
       // button1
       //
       this.button1.Location = new System.Drawing.Point(152, 304);
       this.button1.Name = "button1";
       this.button1.Size = new System.Drawing.Size(72, 64);
       this.button1.TabIndex = 1;
       this.button1.Text = "从数据库表生成XML文档";
       this.button1.Click += new System.EventHandler(this.button1_Click);
       //
       // button2
       //
       this.button2.Location = new System.Drawing.Point(328, 304);
       this.button2.Name = "button2";
       this.button2.Size = new System.Drawing.Size(72, 64);
       this.button2.TabIndex = 2;
       this.button2.Text = "显示生成的XML文档";
       this.button2.Click += new System.EventHandler(this.button2_Click);
       //
       // Form1
       //
       this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
       this.ClientSize = new System.Drawing.Size(584, 445);
       this.Controls.Add(this.button2);
       this.Controls.Add(this.button1);
       this.Controls.Add(this.textBox1);
       this.Name = "Form1";
       this.Text = "从数据库表生成XML文档";
       this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// 应用程序的主入口点。
      /// </summary>
      [STAThread]
      static void Main()
      {
       Application.Run(new Form1());
      }

      private void button1_Click(object sender, System.EventArgs e)
      {
       
       if(this.Connect2DB())
       {
        xmlDoc=new DOMDocument40Class();
        IXMLDOMProcessingInstruction pPI;
        pPI=xmlDoc.createProcessingInstruction("xml","version='1.0' encoding='GB2312' standalone='no'");
        xmlDoc.appendChild(pPI as IXMLDOMNode);
        IXMLDOMComment pComment;
        pComment=xmlDoc.createComment("下面是实例");
        xmlDoc.appendChild(pComment as IXMLDOMNode);
        IXMLDOMElement pElement;
        IXMLDOMElement pElementChild;
        IXMLDOMText pText;
        pElement=xmlDoc.createElement("students");
        xmlDoc.appendChild(pElement as IXMLDOMNode);
                    int count;    
        pRS.MoveFirst();
        while(pRS.EOF==false)
        {
         count=0;
         pElement=xmlDoc.createElement("student");
         foreach(ADODB.Field pField in pRS.Fields)
         {
                            pElementChild=xmlDoc.createElement(pField.Name);
                            pText=xmlDoc.createTextNode(pRS.get_Collect(count).ToString());
          pElementChild.appendChild(pText as IXMLDOMNode);
          count++;
                            pElement.appendChild(pElementChild as IXMLDOMNode);
          //     MessageBox.Show(pField.Name);
         }
         xmlDoc.documentElement.appendChild(pElement as IXMLDOMNode);
         pRS.MoveNext();
        }
        xmlDoc.save(Application.StartupPath+"//"+"test.xml");
        MessageBox.Show("生成成功!");
        pRS.Close();
        pConn.Close();
       }
      
      }
      private bool Connect2DB()
      {
       try
       {
        pConn=new ConnectionClass();
       
        pRS=new ADODB.RecordsetClass();
       
        dbname="students";
        sname="aubs123"+"\\"+"JT";
        pUser="sa";
        pPSW="sa";
        pSelStr="SELECT * From students";

        pConn.Open("Provider=SQLOLEDB.1;Server=" + sname + ";Initial Catalog=" + dbname,pUser,pPSW,-1);
        pRS.Open(pSelStr,pConn,ADODB.CursorTypeEnum.adOpenDynamic,ADODB.LockTypeEnum.adLockOptimistic,-1);
        return true;
       }
       catch
       {
        return false;
       }
      }

      private void button2_Click(object sender, System.EventArgs e)
      {
       this.textBox1.Text=xmlDoc.xml;
      }
    }
    }


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/5/24 15:07:00
     
     typedata 美女呀,离线,快来找我吧!
      
      
      等级:大二期末(Java考了96分!)
      文章:85
      积分:403
      门派:XML.ORG.CN
      注册:2007/1/17

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给typedata发送一个短消息 把typedata加入好友 查看typedata的个人资料 搜索typedata在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看typedata的博客2
    发贴心情 
    执行跟踪,,看程序是卡在哪里嘛,,或者要分析错误提示

    ----------------------------------------------
    DBTwin SQL SERVER 数据库集群系统(纯软件并行双机容错、负载均衡) http://www.zhetides.com.cn

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2011/6/28 11:25:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XML 与 数据库 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/3/28 17:08:28

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms