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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Introduction ( All good things must come to an end ) The original MySQL API has gone away.  It was deprecated (years ago) by PHP in Version 5.5, and removed from PHP in all current releases .  As a result, the issue is upon us today.  It's time to …
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas… provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

724 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