DataTable dt = new DataTable("Student");//DataTable对象,表名为Student
//开始增加列头
dt.Columns.Add("编号",typeof(Int32));
dt.Columns.Add("姓名",typeof(String));
dt.Columns.Add("成绩",typeof(String));
//开始增加行数据
DataRow row = dt.NewRow();
row[0] = 1;
row[1] = "张";
row[2] = "98";
dt.Rows.Add(row);//向DataTable增加第一行记录
row = dt.NewRow();
row[0] = 2;
row[1] = "李";
row[2] = "78";
dt.Rows.Add(row);//向DataTable增加第二行记录
//设置DataTable的主键
dt.PrimaryKey = new DataColumn[]
{
   dt.Columns[0]
};

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
  • 2021-12-29
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2021-11-12
  • 2021-11-26
  • 2022-12-23
相关资源
相似解决方案