asp.net.ph

DataRowCollection.Find Method ( Object [ ] )

System.Data Namespace   DataRowCollection Class


Returns the row containing the specified primary key values.

[ VB ]
Overloads Public Function Find ( _
   ByVal keys ( ) As Object _
) As DataRow

[ C# ]
public DataRow Find (
   object [ ] keys
 );

[ C++ ]
public: DataRow* Find (
   Object* keys __gc [ ]
);

[ JScript ]
public function Find (
   keys : Object [ ]
) : DataRow;

Parameters

keys
An array of primary key values to find. The type of the array is Object.

Return Value

An array of DataRow objects containing the primary key values specified; otherwise a null value if the primary key values do not exist in the DataRowCollection.

Exceptions


Exception Type Condition
IndexOutOfRangeException Occurs when No row corresponds to that index value.

Remarks

To use the Find method, the DataTable object to which the DataRowCollection object belongs to must have at least one column designated as a primary key column. See the PrimaryKey property for details on creating a PrimaryKey column, or an array of DataColumn objects when the table has more than one primary key.

Example

The following example uses the values of an array to find a specific row in a collection of DataRow objects. The method presumes a DataTable exists with three primary key columns. After creating an array of the values, the code uses the Find method with the array to get the particular object desired.

private void FindInMultiPKey ( DataTable myTable ) {
   DataRow foundRow;
   // create an array for the key values to find.
   object [ ] findTheseVals = new object [ 3 ];
   // set the values of the keys to find.
   findTheseVals [ 0 ] = "John";
   findTheseVals [ 1 ] = "Smith";
   findTheseVals [ 2 ] = "5 Main St.";
   foundRow = myTable.Rows.Find ( findTheseVals );
   // display column 1 of the found row.
   if ( foundRow != null )
      Response.Write ( foundRow [ 1 ] );
}
  C# VB

See Also

DataRowCollection Members   DataRowCollection.Find Overload List   DataTable   PrimaryKey   Contains Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph