??????11??Sort row
????dt.DefaultView.Sort = "ID ??Name ASC";
????dt=dt.DefaultView.ToTable();
??????12??Bind DataTable
????//?????????DefaultView
????gvTestDataTable.DataSource = dt;
????gvTestDataTable.DataBind();
??????13??judge the DataTable’s Column name is a string
????//?ж?????????????DataTable??????
????dtInfo.Columns.Contains("AX");
??????14??DataTable convert to XML and XML convert to DataTable
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;
}
??????15????DataTable????в??????DataTable??
????????1??
????// <summary>
????// ???DataTable?е????????μ?DataTable
????// </summary>
????// dt ???????DataTable
????// condition ????????
????DataTable newdt = new DataTable();
????newdt = dt.Clone(); // ???dt ????????????? dt ???????????????????
????DataRow[] rows = dt.Select(conditions); // ??dt ?в????????????????
????foreach (DataRow row in rows)  // ?????????????dt?У?
????{
????newdt.Rows.Add(row.ItemArray);
????}
????????2??
????DataTable newdt = new DataTable();
????newdt=dt.Clone();
????DataRow[] dr = dt.Select(condition);
????for(int i=0;i<dr.Length;i++)
????{
????newdt.ImportRow((DataRow)dr[i]);
????}
????????3??
????DataTable newdt = new DataTable();
????dt.DefaultView.RowFilter = "conditions";
????newdt =dt.DefaultView.ToTable();
??????16?????DataTable?е???:
???????DataTable?е??????????????DataTable.Rows.Remove(DataRow dr)??DataTable.Rows.RemoveAt(i)??DataRow.Delete()??
???????DataTable?е?????????????????????????????
????1????for????????????????????????????????DataTable.Rows.RemoveAt(i)????
????2????DataTable??Select?????????÷???????????????????
????3??Delete()??????datatable.AccepteChanges()??????????????????Delete()????????е?????????????????????datatable.RejectChanges()???????????????????????????У???????????Delete()????????AccepteChanges()????????????