复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt_AX = new DataTable();
//dt_AX.Columns.Add("Sex", typeof(System.Boolean));
//DataRow dr = dt_AX.NewRow();
//dr["Sex"] = true;
//dt_AX.Rows.Add(dr);
string xml=ConvertBetweenDataTableAndXML_AX(dt_AX);
DataTable dt = ConvertBetweenDataTableAndXML_AX(xml);
}
public string ConvertBetweenDataTableAndXML_AX(DataTable dtNeedCoveret)
{
System.IO.TextWriter tw = new System.IO.StringWriter();
//if TableName is empty, WriteXml() will throw Exception.
dtNeedCoveret.TableName=dtNeedCoveret.TableName.Length==0?"Table_AX":dtNeedCoveret.TableName;
dtNeedCoveret.WriteXml(tw);
dtNeedCoveret.WriteXmlSchema(tw);
return tw.ToString();
}
public DataTable ConvertBetweenDataTableAndXML_AX(string xml)
{
System.IO.TextReader trDataTable = new System.IO.StringReader(xml.Substring(0, xml.IndexOf("<?xml")));
System.IO.TextReader trSchema = new System.IO.StringReader(xml.Substring(xml.IndexOf("<?xml")));
DataTable dtReturn = new DataTable();
dtReturn.ReadXmlSchema(trSchema);
dtReturn.ReadXml(trDataTable);
return dtReturn;
}
新闻热点
疑难解答
图片精选