思路:先将datatable转换为xml格式字符串,然后在比较xml即可
DataTable dt = new DataTable(); dt.TableName = "dt"; //需要设置DataTable的名称 dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Rows.Add(new string[] { "1", "James" }); dt.Rows.Add(new string[] { "2", "Mary" }); //转换为字符串 StringBuilder sb = new StringBuilder(); TextWriter tw = new StringWriter(sb); dt.WriteXml(tw); tw.Close();