日期:2014-05-17 浏览次数:20801 次
XmlNode root = doc.SelectSingleNode(doc.DocumentElement.Name); DataTable dt = new DataTable(); dt.TableName = "初中成绩"; //dt.Columns.Add(new DataColumn(root.ChildNodes[0].Attributes[0].Name, typeof(string))); XmlNode node_1_1 = doc.SelectSingleNode(doc.DocumentElement.Name + "/" + doc.DocumentElement.FirstChild.Name + "/" + doc.DocumentElement.FirstChild.FirstChild.Name); XmlNodeList nodelist_1_1 = node_1_1.ChildNodes; for (int i = 0; i < 2; i++) { dt.Columns.Add(new DataColumn(node_1_1.ChildNodes[i].Name, typeof(string))); } DataRow dr = dt.NewRow(); foreach (XmlNode xn in nodelist_1_1) { foreach (DataColumn column in dt.Columns) { if (xn.LocalName == column.ColumnName) { dr[column] = xn.InnerText.ToString().Trim(); dt.Rows.Add(dr); } } }
DataTable dt = new DataTable("初中成绩");
DataColumn Column = new DataColumn();
Column.ColumnName = "name";
Column.DataType = System.Type.GetType("System.String");
&nbs