Can you use DataTable.Contains(object key) if your datatable's primary key is two columns?

你。 提交于 2019-12-22 06:33:13

问题


if so how?


回答1:


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




回答2:


'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




回答3:


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



来源:https://stackoverflow.com/questions/917622/can-you-use-datatable-containsobject-key-if-your-datatables-primary-key-is-tw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!