Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query A DataTable
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01384878
Message ID:
01384934
Vues:
38
>I have a stored proc that returns the result of a JOIN from a SQL Server database. The data represents products and parts. It's possible to have one or many products returned, and all the parts that correspond to each product. So it will either be a many to many, or a one to many.
>
>Once the data is in ADO, I want to be able to determine of I got back more than one product. So far I have to following code, but to me it seems rather inefficient:
>

You can use LINQ to do this. Here's a sample:
DataTable table = new DataTable();
table.Columns.Add("Id", typeof(int));
table.Columns.Add("Detail", typeof(string));

DataRow row = table.NewRow();
row["Id"] = 1;
row["Detail"] = "Item 1";
table.Rows.Add(row);
row = table.NewRow();
row["Id"] = 1;
row["Detail"] = "Item 2";
table.Rows.Add(row);

int count = table.AsEnumerable().Count(r => row.Field<int>("Id") == 1);
In your case, something like this might work:
string product = "SomeProductID";
int count = table.AsEnumerable().Count(r => row.Field<string>("Product_Number") == product);
But, like the other suggestions, it may be simpler/better to do this in the initial query.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform