当前位置:首页
开发技术指南» 文章正文
    引言:
 

 

 ·哇噻我的可用分居然有11625    »显示摘要«
    摘要: rt ......
 ·这个select该如何写    »显示摘要«
    摘要: 在table1中存在f1,f2,f3等字段 其中f1是个标识字段,表示纪录的类型,f2是外部编号,f3是内部编号 如果f1==1则表示该纪录有外部编号,也有内部编号 如果f1==2则表示该纪录只存在内部编号 我想对这个表进行查询,如果f1==1就显示f2,如果f1==2就显示f3,然后显示在一个结果中。 比如 f1 f2 f3 1 a1 b1 2 c2 我想得到如下的结果 f1 numb......


如何把一个XML字符串表示的数据集添加到一个Dataset中指定的Table中

一个Dataset中指定的Table中已存在部分数据,XML字符串表示的数据集将追加到该Table中。

NO.1   作者: snof

一样:  
  这是读取的方法:  
  private   void   DemonstrateReadWriteXMLDocumentWithXMLReader(){  
        //   Create   a   DataSet   with   one   table   and   two   columns.  
        DataSet   OriginalDataSet   =   new   DataSet("myDataSet");  
          OriginalDataSet.Namespace=   "NetFrameWork";  
        DataTable   myTable   =   new   DataTable("myTable");  
        DataColumn   c1   =   new   DataColumn("id",   Type.GetType("System.Int32"));  
        c1.AutoIncrement=   true;  
        DataColumn   c2   =   new   DataColumn("item");  
        myTable.Columns.Add(c1);  
        myTable.Columns.Add(c2);  
        OriginalDataSet.Tables.Add(myTable);  
        //   Add   ten   rows.  
        DataRow   newRow;  
        for(int   i   =   0;   i   <   10;   i++){  
              newRow   =   myTable.NewRow();  
              newRow["item"]=   "item   "   +   i;  
              myTable.Rows.Add(newRow);  
        }  
        OriginalDataSet.AcceptChanges();  
        //   Print   out   values   of   each   table   in   the   DataSet   using   the    
        //   function   defined   below.  
        PrintValues(OriginalDataSet,   "Original   DataSet");  
        //   Write   the   XML   schema   and   data   to   file   with   FileStream.  
        string   xmlFilename   =   "myXmlDocument.xml";  
        //   Create   FileStream          
        System.IO.FileStream   fsWriteXml   =   new   System.IO.FileStream  
              (xmlFilename,   System.IO.FileMode.Create);  
        //   Create   an   XmlTextWriter   to   write   the   file.  
        System.Xml.XmlTextWriter   xmlWriter   =   new   System.Xml.XmlTextWriter  
              (fsWriteXml,   System.Text.Encoding.Unicode);  
        //   Use   WriteXml   to   write   the   document.  
        OriginalDataSet.WriteXml(xmlWriter);  
        //   Close   the   FileStream.  
        fsWriteXml.Close();  
               
        //   Dispose   of   the   original   DataSet.  
        OriginalDataSet.Dispose();  
        //   Create   a   new   DataSet.  
        DataSet   newDataSet   =   new   DataSet("New   DataSet");  
               
        //   Read   the   XML   document   back   in.    
        //   Create   new   FileStream   to   read   schema   with.  
        System.IO.FileStream   fsReadXml   =   new   System.IO.FileStream  
              (xmlFilename,   System.IO.FileMode.Open);  
        //   Create   an   XmlTextReader   to   read   the   file.  
        System.Xml.XmlTextReader   myXmlReader   =    
              new   System.Xml.XmlTextReader(fsReadXml);  
        //   Read   the   XML   document   into   the   DataSet.  
        newDataSet.ReadXml(myXmlReader);  
        //   Close   the   XmlTextReader  
        myXmlReader.Close();  
   
        //   Print   out   values   of   each   table   in   the   DataSet   using   the    
        //   function   defined   below.  
        PrintValues(newDataSet,"New   DataSet");  
  }  
   
  private   void   PrintValues(DataSet   ds,   string   label){  
        Console.WriteLine("\n"   +   label);  
        foreach(DataTable   t   in   ds.Tables){  
              Console.WriteLine("TableName:   "   +   t.TableName);  
              foreach(DataRow   r   in   t.Rows){  
                    foreach(DataColumn   c   in   t.Columns){  
                          Console.Write("\t   "   +   r[c]   );  
                    }  
                    Console.WriteLine();  
              }  
        }  
  }  
  读取以后用DataSet的Merge方法就会把数据合并起来  
  3..然后再写进XML  
  以下示例创建   System.IO.FileStream   对象,该对象用于创建新的   System.Xml.XmlTextWriter。XmlTextWriter   对象和   WriteXml   方法一起用于写   XML   文档。  
   
  [Visual   Basic,   C#]   注意       此示例显示如何使用   WriteXml   的一个重载版本。有关其他可用示例,请参阅单独的重载主题。  
  [Visual   Basic]    
  Private   Sub   WriteXmlToFile(thisDataSet   As   DataSet)  
          If   thisDataSet   Is   Nothing   Then  
                  Return  
          End   If  
            Create   a   file   name   to   write   to.  
          Dim   filename   As   String   =   "myXmlDoc.xml"  
            Create   the   FileStream   to   write   with.  
          Dim   myFileStream   As   New   System.IO.FileStream   _  
                (filename,   System.IO.FileMode.Create)  
            Create   an   XmlTextWriter   with   the   fileStream.  
          Dim   myXmlWriter   As   New   System.Xml.XmlTextWriter   _  
                (myFileStream,   System.Text.Encoding.Unicode)  
            Write   to   the   file   with   the   WriteXml   method.  
          thisDataSet.WriteXml(myXmlWriter)  
          myXmlWriter.Close()  
  End   Sub  
  [C#]    
  private   void   WriteXmlToFile(DataSet   thisDataSet)   {  
          if   (thisDataSet   ==   null)   {   return;   }  
          //   Create   a   file   name   to   write   to.  
          string   filename   =   "myXmlDoc.xml";  
          //   Create   the   FileStream   to   write   with.  
          System.IO.FileStream   myFileStream   =   new   System.IO.FileStream  
                (filename,   System.IO.FileMode.Create);  
          //   Create   an   XmlTextWriter   with   the   fileStream.  
          System.Xml.XmlTextWriter   myXmlWriter   =    
                new   System.Xml.XmlTextWriter(myFileStream,   System.Text.Encoding.Unicode);  
          //   Write   to   the   file   with   the   WriteXml   method.  
          thisDataSet.WriteXml(myXmlWriter);        
          myXmlWriter.Close();  
    }  
 


 ·挑战高难度,关于表得更新    »显示摘要«
    摘要: 比如我得数据库里有a,b,c,d,e,f等几张表,每张表里都有10000条记录。 由于种种原因,我需要对a,c,e,f几张表中符合条件得记录进行修改,(注:都是单表更新)。这种情况下我们显然没必要,也不可能用数据窗口对象,和数据窗口控件来做。你不可能把每张表都用一个datawindow对象对应起来,而且事实上更通常得情况下,我事先更本不知道需要更新哪些表,我把需要更新得表放在配置文件中,那......
» 本期热门文章:

©2000-2007 All Rights Reserved. 最佳浏览:1024X768 MSIE