Can you use DataTable.Contains(object key) if your

2019-04-29 21:54发布

3条回答
霸刀☆藐视天下
2楼-- · 2019-04-29 22:27

I assume you're referring to the DataRowCollection.Contains method ? There is an overload that takes an array of objects, you should use this one

查看更多
欢心
3楼-- · 2019-04-29 22:30

To select by a primary key you should use one of:

  • DataTable.Rows.Find(Object) in case your PK is one column
  • DataTable.Rows.Find(Object[]) in case you have more then 1 column as a primary key

In case of a typed DataSet, the method MyDataTable.Rows.Find(...) will be generated for you with the proper signature. Basically it is a method on DataRowCollection class

查看更多
闹够了就滚
4楼-- · 2019-04-29 22:49

'Contains' does not seem to be a member of the DataRow class (maybe this is a typed data set?)

In any case, you can always use (DataTable.Select(....).Length > 0) as a substitute

查看更多
登录 后发表回答