Solved

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

Posted on 2010-08-27
5
496 Views
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");

ptslv
0
Comment
Question by:ptslv
5 Comments
 
LVL 5

Accepted Solution

by:
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
0
 
LVL 35

Expert Comment

by:YZlat
ID: 33543326
you can use Select method of a dataset

http://msdn.microsoft.com/en-us/library/t5ce3dyt(vs.71).aspx
0
 
LVL 35

Expert Comment

by:YZlat
ID: 33543342
Another way is to just use DataView to filter data from your DataSet
0
 
LVL 3

Expert Comment

by:ahll
ID: 33570204
Hi,

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?
0
 

Author Closing Comment

by:ptslv
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.

ptslv
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Wufoo.com 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.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

785 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