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

Slim picture Slim · May 27, 2009 · Viewed 14.2k times · Source

if so how?

Answer

van picture van · May 27, 2009

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