Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Find a record
Message
From
02/09/2003 10:46:05
 
 
To
02/09/2003 08:33:47
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Miscellaneous
Thread ID:
00825256
Message ID:
00825319
Views:
20
>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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform