Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Find a record
Message
 
 
À
02/09/2003 08:33:47
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Divers
Thread ID:
00825256
Message ID:
00825319
Vues:
19
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform