C# DataTable??????÷?????
???????????? ???????[ 2016/7/19 10:40:39 ] ??????????????????? .NET
??????????о??????DataTable?????DataTable??????????????????????????????????????????°?????Ч???????DataTable????ü????????????
???????DataTable???
????(1)????????
????DataTable() ?????????????DataTable ??????????
????DataTable(string tableName) ???????????????DataTable ??????????
????DataTable(string tableName?? string tableNamespace) ???????????????????????DataTable??????????
????(2) ????????
????CaseSensitive ?????е?????????????????Сд??
????ChildRelations ?????DataTable ????????????
????Columns ???????????е?????
????Constraints ?????????????????????
????DataSet ???????????DataSet??
????DefaultView ??????????????????α?λ???????????????
????HasErrors ??????????????????????DataSet ???κα???κ?????????д???
????MinimumCapacity ???????????????????С????????е???????С??????? 50??
????Rows ???????????е?????
????TableName ?????????DataTable ???????
????(3)???÷???
????AcceptChanges() ??????ε???AcceptChanges() ??????????е????и????
????BeginInit() ?????????????????????????????????DataTable????????????????????
????Clear() ????????????DataTable??
????Clone() ???DataTable ?????????????DataTable ??????????
????EndInit() ?????????????????????????????DataTable ??????????????????????????
????ImportRow(DataRow row) ??DataRow ?????DataTable ?У??????κ???????????????????????
????Merge(DataTable table) ???????DataTable ?????DataTable ?????
????NewRow() ?????????????????????DataRow??
????????DataTable??ü???
??????1??Create a DataTable
????DataTable dt = new DataTable("Table_AX");
??????2??Add columns for DataTable
????//Method 1
????dt.Columns.Add("column0"?? System.Type.GetType("System.String"));
????//Method 2
????DataColumn dc = new DataColumn("column1"?? System.Type.GetType("System.Boolean"));
????dt.Columns.Add(dc);
??????3??Add rows for DataTable
????//Initialize the row
????DataRow dr = dt.NewRow();
????dr["column0"] = "AX";
????dr["column1"] = true;
????dt.Rows.Add(dr);
????//Doesn't initialize the row
????DataRow dr1 = dt.NewRow();
????dt.Rows.Add(dr1);
??????4??Select row
????//Search the second row ?????и????????is null??select
????DataRow[] drs = dt.Select("column1 is null");
????DataRow[] drss = dt.Select("column0 = 'AX'");
??????5??Copy DataTable include data
????DataTable dtNew = dt.Copy();
??????6??Copy DataTable only scheme
????DataTable dtOnlyScheme = dt.Clone();
??????7??Operate one row
????//??dt?????
????//Method 1
????DataRow drOperate = dt.Rows[0];
????drOperate["column0"] = "AXzhz";
????drOperate["column1"] = false;
????//Method 2
????drOperate[0] = "AXzhz";
????drOperate[1] = false;
????//Method 3
????dt.Rows[0]["column0"] = "AXzhz";
????dt.Rows[0]["column1"] = false;
????//Method 4
????dt.Rows[0][0] = "AXzhz";
????dt.Rows[0][1] = false;
??????8??Evaluate another DataTable's row to current Datatable
????dtOnlyScheme.Rows.Add(dt.Rows[0].ItemArray);
??????9??Convert to string
????System.IO.StringWriter sw = new System.IO.StringWriter();
????System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(sw);
????dt.WriteXml(xw);
????string s = sw.ToString();
??????10??Filter DataTable
????dt.DefaultView.RowFilter = "column1 <> true";
????dt.DefaultView.RowFilter = "column1 = true";
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11