关于DataTable操作用了一遍又一遍,每次都是现查,尽管很容易查也很简单
坏习惯,要改!要记住!不允许一个地方摔多个跟头!
dt = new DataTable();
/*加列*/
dt.Columns.Add("BT", Type.GetType("System.String")); dt.Columns.Add("BR", Type.GetType("System.String")); dt.Columns.Add("BZ", Type.GetType("System.String")); dt.Columns.Add("YL", Type.GetType("System.String")); dt.Columns.Add("DW", Type.GetType("System.String")); /*加行*/ DataRow dr = dt.NewRow(); dr["BT"] = "总井数"; dr["BR"] = "27291"; dr["BZ"] = ""; dr["YL"] = ""; dr["DW"] = "口"; dt.Rows.Add(dr); DataRow dr1 = dt.NewRow(); dr1["BT"] = "开井数"; dr1["BR"] = "20291"; dr1["BZ"] = "-10"; dr1["YL"] = ""; dr1["DW"] = "口"; dt.Rows.Add(dr1); DataRow dr2 = dt.NewRow(); dr2["BT"] = "开井率"; dr2["BR"] = "75.28"; dr2["BZ"] = "0.03"; dr2["YL"] = "74.28"; dr2["DW"] = "%"; dt.Rows.Add(dr2); /*设置主键*/ dt.PrimaryKey = new DataColumn[] { dt.Columns["BT"] };