加为好友
发送私信
在线聊天
发表于:2008-07-09 16:58:34 11 楼 得分:40
以下是我 写的 读写 XML 共通 参考下 public class MCHBaseClass { private DataSet ds = new DataSet(); private string mPath = ""; public DataSet getDS() { return ds; } /// <summary> /// 加载获取的MXL 获取XML路径 /// </summary> /// <param name="path"> </param> public void LoadSetting(string path) { this.mPath = path; this.ds = new DataSet(); try { ds.ReadXml(@mPath); } catch (Exception ex) { System.Console.WriteLine(ex.Message); throw; } } public DataTable Getting(string fNode) { DataTable dt = new DataTable(); try { dt = ds.Tables[fNode]; return dt; } catch (Exception ex) { System.Console.WriteLine(ex.Message); throw; } } /// <summary> /// 获取fNode父节点下第intKey行 strSection的属性值 /// </summary> /// <param name="fNode">父节电名称 </param> /// <param name="intKey">行数 </param> /// <param name="strSection">属性名称 </param> /// <returns> </returns> public string Getting(string fNode, int intKey, string strSection) { string strValue = ""; try { strValue = Convert.ToString(ds.Tables[fNode].Rows[intKey][strSection]); return strValue; } catch (Exception ex) { System.Console.WriteLine(ex.Message); throw; } } /// <summary> /// 把ds写到路径mPath下,保存成XML /// </summary> /// <param name="ds1"> </param> /// <param name="mPath1"> </param> public void SaveSettings(DataSet ds1, string mPath1) { try { ds1.WriteXml(@mPath1); } catch (Exception ex) { System.Console.WriteLine(ex.Message); throw; } } /// <summary> /// 更改父节点为fNode 第intKey行 strSection属性值 为strDefaultValue /// </summary> /// <param name="fNode">父节点名称 </param> /// <param name="intKey">行数 </param> /// <param name="strSection">属性名称 </param> /// <param name="strDefaultValue">更改的值 </param> public void SetSetting(string fNode, int intKey, string strSection, string strDefaultValue) { try { ds.Tables[fNode].Rows[intKey][strSection] = strDefaultValue; ds.AcceptChanges(); this.SaveSettings(ds,mPath); } catch (Exception ex) { System.Console.WriteLine(ex.Message); throw; } } /// <summary> /// 在父节点为fNode intKey行 添加 属性名称strSection 值strDefaultValue /// </summary> /// <param name="fNode">父节点名称 </param> /// <param name="intKey">行数 </param> /// <param name="strSection">添加的属性名称 </param> /// <param name="strDefaultValue">属性值 </param> public void AddSettings(string fNode, int intKey, string strSection, string strDefaultValue) { try { ds.Tables[fNode].Columns.Add(strSection); ds.Tables[fNode].Rows[intKey][strSection] = strDefaultValue; ds.AcceptChanges(); this.SaveSettings(ds, mPath); } catch (Exception ex) { System.Console.WriteLine(ex.Message); throw; } } /// <summary> /// 删除父节点为fNode下的 属性值strSection /// </summary> /// <param name="fNode"> </param> /// <param name="strSection"> </param> public void DeleteSettings(string fNode, string strSection) { try { ds.Tables[fNode].Columns.Remove(strSection); ds.AcceptChanges(); this.SaveSettings(ds, mPath); } catch (Exception ex) { System.Console.WriteLine(ex.Message); throw; } } }
修改
删除
举报
引用
回复