private static DataTable DtOpenMenu = new DataTable("Menu");
//datatable中是否存在列明,如果不存在则新增
if (!DtOpenMenu.Columns.Contains("TreeTitle")) {
DataColumn dc = null;
dc = DtOpenMenu.Columns.Add("TreeTitle", Type.GetType("System.String"));
dc = DtOpenMenu.Columns.Add("Title", Type.GetType("System.String"));
dc = DtOpenMenu.Columns.Add("LocationHref", Type.GetType("System.String"));
}
//循环进行修改
for (int i = 0; i < drs2.Length; i++)
{
DataRow drEmployee = drs2[i];
drEmployee.BeginEdit();
drEmployee["TreeTitle"] = TreeTitle;
drEmployee["Title"] = Title;
drEmployee["LocationHref"] = LocationHref;
drEmployee.EndEdit();
}
//进行添加新行
DtOpenMenu.Rows.Add(new object[] {""+ treeTitle + "", ""+ title + "", ""+ locationHref + "" });
#region 复制DataRow的表结构
public DataTable ToDataTable(DataRow[] rows)
{
if (rows == null || rows.Length == 0) return null;
DataTable tmp = rows[0].Table.Clone(); // 复制DataRow的表结构
foreach (DataRow row in rows)
tmp.Rows.Add(row.ItemArray); // 将DataRow添加到DataTable中
return tmp;
}
#endregion