>To find a record (Not Key) in a datatable, I'm doing the following :
>1) use dataview rowfilter property to filter the datatable.
>2) get the key fields values of the record.
>3) use the find method to locate the the record.
>
>Is this OK?
>Is there a better or easier way?
What I've been trying is this:
string CommandString = "SELECT * FROM Customers";
SqlConnection Connection = new SqlConnection("server=(local);database=Northwind;Integrated Security=SSPI");
SqlCommand Command = new SqlCommand(CommandString,Connection);
SqlDataAdapter DataAdapter = new SqlDataAdapter(Command);
DataSet dsCustomer;
DataTable dtCustomer;
DataAdapter.Fill(dsCustomer,"Customers");
dtCustomer = dsCustomer.Tables["Customers"];
DataRow[] drSelected;
drSelected = dtCustomer.Select("City='barcelona'");
Console.WriteLine("Key for selected record is: {0}",
drSelected[0]["CustomerID"]);
Your question implies that yoiur filter condition returns only one row in the array, so this technique allows you to skip the second step of using the Find() method, with the desired DataRow as the first (and only) element of the array.
>>-Steve->>
Steve Sawyer
Geeks and Gurus, Inc.