How to query a query result set in ASP.NET C#

Posted on 2010-08-27
Last Modified: 2012-05-10
I have a dataset result from a query that I am querying to get counts for a webpage.  I am getting an error referencing the ds.  What is the proper way to reference a ds from a query?

here is my code:

SqlDataAdapter da = new SqlDataAdapter(strSQL,con);
da.Fill(ds,"FlagCnts"); // Flag counts of Surveys completed
// count of total flags for records for Surveys completed  by form
strSQL = "SELECT Form, Sum(A_Flag) AS SumOfA_Flag, Sum(L_Flag) AS SumOfL_Flag, Sum(Q_Flag) AS SumOfQ_Flag, Sum(W_Flag) AS SumOfW_Flag, Sum(O_Flag) AS SumOfO_Flag, Sum(D_Flag) AS SumOfD_Flag FROM FlagCnts GROUP BY  Form;";

da = new SqlDataAdapter(strSQL, con);
da.Fill(ds, "TotalFlaggedRecs");

Question by:ptslv

Accepted Solution

Akin Delu earned 500 total points
ID: 33542796
SqlDataAdapter da = new SqlDataAdapter(strSQL,con);
da.Fill(ds,"FlagCnts"); // Flag counts of Surveys completed
int count = da.Table[0].Rows.Count //this will return number of record
LVL 35

Expert Comment

ID: 33543326
you can use Select method of a dataset
LVL 35

Expert Comment

ID: 33543342
Another way is to just use DataView to filter data from your DataSet

Expert Comment

ID: 33570204

I'd say you could combine both queries in just one, so you wont need to access the results from the first query within a second one.
Can you post here the actual SQL you are running the first time?

Author Closing Comment

ID: 33598385
I was already doing this to a pont.  I was trying to set up another dataset where I did not need to.  Thanks for the assistance.


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Deploying to Azure 3 39
Obtain cell value using column ID in DataGrid using VB.NET 2 25
Function after success of Jquery/AJAX action 9 28
IEnumerable<T> to a List<T> 8 40
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
This video teaches users how to migrate an existing Wordpress website to a new domain.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question