RT
我现在实现的时候,后面的记录总会覆盖前面的纪录,导致xml文件中只有一条记录。

解决方案 »

  1.   

    //****你先将数据保存到dataset中,然后在一起动态生成xml文件就可以了.
      

  2.   

    先加载xml到dataset 
    操作dataset
    dataset写回xml
      

  3.   

    可能是我没说清楚,我现在用的dataset只有一行记录,插入到xml后,dataset的内容更新,然后将更新后的内容再次插入到xml时,会把前面的xml中的记录覆盖,现在不能合并dataset,只能一次一次的插入。
      

  4.   

    你对xml的操作估计有误
    看看。。
      

  5.   

    OperateDB.OpenConnection();
    string sql="select BusinessID,BusinessName from ApplyCompanyBaseInfo where BusinessName='"+businessname+"'";
    SqlDataAdapter sda=new SqlDataAdapter(sql,OperateDB.sConnection);
    DataSet ds=new DataSet();
    sda.Fill(ds);
    if(ds.Tables[0]!=null && ds.Tables[0].Rows.Count>0)
    {
    ds.WriteXml(Server.MapPath("../GetDataFromNet/CompanyInfo.xml"));
    } string sql2="select co_name,BusinessID,ctype,ProNameID,co_tel,ApplyType,license_id,award_date,term,archivesID,detail from co where co_name='"+businessname;
    SqlDataAdapter sda2=new SqlDataAdapter(sql2,OperateDB.sConnection);
    DataSet ds2=new DataSet ();
    sda2.Fill(ds2);
    if(ds2.Tables[0]!=null && ds2.Tables[0].Rows.Count>0)
    {
    ds2.WriteXml(Server.MapPath("../GetDataFromNet/coinfo.xml"));
    }这就是我向xml写数据的代码,不知道是为什么,是不是要设置一些参数呀
      

  6.   

    两次重写xml文件,当然会覆盖啊,在第二个dataset初始化时,把xml数据先读进去,然后再操作dataset添加数据,最后生成xml
      

  7.   

    你可以通过dataview来进行中间数据的转换!你2次的数据需要分步显示吗?
    还有GetDataFromNet/coinfo.xml"和GetDataFromNet/CompanyInfo.xml不是同一个文件阿!
      

  8.   

    using System;
    using System.Data;
    using System.Xml;
    using Northwind.FillOrder;public class Sample
    {
      public static void Main()
      {
        OrderDetail orderDS = new OrderDetail(); // 强制类型DATASET    XmlDataDocument xmlDocument = new XmlDataDocument(orderDS);     xmlDocument.Load("Order.xml");    foreach (OrderDetail.LineItem orderItem in orderDS.LineItems)
        {
          OrderDetail.Product product = orderItem.Product;      // Remove quantity from the current stock.
          product.UnitsInStock = (short)(product.UnitsInStock - orderItem.Quantity);      // If the remaining stock is less than the reorder level, order more.
          if ((product.UnitsInStock + product.UnitsOnOrder) < product.ReorderLevel)
            product.UnitsOnOrder = (short)(product.UnitsOnOrder + product.ReorderLevel);
        }    xmlDocument.Save("Order_out.xml");
      }
    }
    我查了下MSDN,上面有一种方法可以实现DATASET和XML的同步问题!建议兄弟去MSDN上查下,可能还有一些方法没有看到!
      

  9.   

    DataSet data = new DataSet();
                    data.ReadXml(xmlPath);
                    DataRow row = data.Tables[0].NewRow();
    //為row插入數據
    row["fdsa"]="fdasfdsa";
    row["aaa"]="fdasfdsa";
    row["aaaaa"]="fdasfdsa";                data.Tables[0].Rows.InsertAt(row,0);
                    data.WriteXml(xmlPath);
      

  10.   

    以下是我写的向XML文件插入数据的代码,希望对你有启发。private void Button1_Click(object sender, System.EventArgs e)
    {
             XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(Server.MapPath("/Forum.xml")); XmlElement xmlele = xmlDoc.CreateElement("forum"); XmlAttribute attForumID = xmlDoc.CreateAttribute("forumID");
    attForumID.Value = "11";
    xmlDoc.DocumentElement.SetAttributeNode(attForumID);

    xmlele.SetAttribute("ForumID","11111");
    xmlDoc.DocumentElement.AppendChild(xmlele);
    xmlDoc.Save(Server.MapPath/Forum.xml"));
    }