Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query A DataTable
Message
De
07/03/2009 16:24:15
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01384878
Message ID:
01386449
Vues:
31
I think that everyone is missing the point. The point is that your DataSet is not normalized and is returning only one DataTable. Therefore, even if you have only one product, every row in your DataTable will contain the same Product Number, so finding a count of distinct entries is pointless.

You really only have two options:

1) If you absolutely insist on returning aggregated data this way, then use the code you posted. It works fine.
-or-
2) Change your Stored Proc to return one extra table containing all the Product Numbers in your query. So, if you only have one product, that extra DataTable in your DataSet will only contain one row. This is definitely the preferred method.

~~Bonnie




>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:
>
>
>bool bMultiProductDS = false;
>
>// Get the first prod number
>string sFirstProductNumber = dsResults.Tables[0].Rows[0]["Product_Number"].ToString().ToLower();
>
>// Define a variable to hold subsequent product numbers
>string sNextProductNumber = "";
>
>// Define a row counter
>int iRow = 0;
>
>// Loop once for each row in the firs table
>foreach(DataRow oRow in dsResults.Tables[0].Rows)
>{
>    // Skip the first row
>    if (iRow == 0)
>    {
>        iRow++;
>        continue;
>    }
>
>    // Get the next product number
>    sNextProductNumber = oRow["Product_Number"].ToString().ToLower();
>
>    if (sFirstProductNumber != sNextProductNumber) ;
>    {
>        bMultiProductDS = true;
>        break;
>    }
>}
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform