16,553
社区成员
发帖
与我相关
我的任务
分享
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("客户A", typeof(string));
dt.Rows.Add(1, "A1");
dt.Rows.Add(2, "A2");
dt.Rows.Add(3, "A3");
dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] };
DataTable dt2 = new DataTable();
dt2.Columns.Add("ID", typeof(int));
dt2.Columns.Add("客户B", typeof(string));
dt2.Rows.Add(1, "B1");
dt2.Rows.Add(2, "B2");
dt2.Rows.Add(4, "B4");
dt2.PrimaryKey = new DataColumn[] { dt2.Columns["id"] };
dt.Merge(dt2);
DataGrid DataGrid1 = new DataGrid();
this.form1.Controls.Add(DataGrid1);
DataGrid1.DataSource = dt.DefaultView;
DataGrid1.DataBind();