如果DataTable没有主键,那么在Fill方法后将把检索出的记录行和列添加到现在的DataTable中.

想要指定主键有两种方式:

(1)设置da.MissingSchemaAction=System.Data.MissingSchemaAction.AddWithKey,默认是Add.

(2)在首次Fill之后定义数据表的主键约束

   da.Fill(ds,"author");
   ds.Tables[0].PrimaryKey=new DataColumn[]{ds.Tables[0].Columns[0]};

这样以后将后在Fill之后跟据主键更新数据集,而不是简单的追加.

相关文章:

  • 2022-12-23
  • 2021-08-07
  • 2021-06-21
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
  • 2021-05-09
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案