对于table.LoadDataRow (obj,null)的解释是:
当table中没有主键时就插入该新行,有主键时就更新对应行
DataTable table = new DataTable();
DataColumn col1 = new DataColumn("id", typeof(string));
DataColumn col2 = new DataColumn("name", typeof(string));
DataColumn col3 = new DataColumn("age", typeof(int));
table.Columns.Add(col1);
table.Columns.Add(col2);
table.Columns.Add(col3);
//给datatable设置主键
DataColumn[] key = new DataColumn[1];
key[0] = col1;
table.PrimaryKey = key;
//table.PrimaryKey = new DataColumn[] { table.Columns["id"] };
DataRow row = table.NewRow();
row[col1] = "G001";
row[col2] = "yanxiangliang";
row[col3] = "31";
table.Rows.Add(row);