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上查下,可能还有一些方法没有看到!
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);
操作dataset
dataset写回xml
看看。。
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写数据的代码,不知道是为什么,是不是要设置一些参数呀
还有GetDataFromNet/coinfo.xml"和GetDataFromNet/CompanyInfo.xml不是同一个文件阿!
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上查下,可能还有一些方法没有看到!
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);
{
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"));
}