473,399 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

DataAdapter, limiting results, but getting the total count row.

I'm using a DataAdapter to fill a DataSet to display a list of items
in a custom way. I'm not using the GridView or any server controls
like that.

This is my code:
<code>
SqlConnection sqlConn =
DatabaseControl.Database.GetConnection(Globals.dbC onn);
SqlCommand cmdTitles = new SqlCommand();
cmdTitles.CommandText = "SelectTitlesByCategory";
cmdTitles.CommandType = CommandType.StoredProcedure;

cmdTitles.Parameters.Add("@alpha", SqlDbType.VarChar, 25);
cmdTitles.Parameters["@alpha"].Value = alpha;

cmdTitles.Parameters.Add("@cat_id", SqlDbType.Int, 16);
cmdTitles.Parameters["@cat_id"].Value = cat_id;

cmdTitles.Connection = sqlConn;

DataSet dsTitles = new DataSet();
SqlDataAdapter adptTitles = new SqlDataAdapter(cmdTitles);

adptTitles.Fill(dsTitles, start, length, "titles");

</code>

Now this works great, but now for me to enable my paging, I need a way
to get a count of how many rows would have been retrieved if the
DataAdapter didn't limit the results. I want to avoid making a second
query, and I don't want to have to make a new stored procedure if
possible. Is there a way to acccomplish this?

Justin

Apr 2 '07 #1
1 4436
You need to alter your stored proc so that it returns 2 resultsets - one with
the data you've asked for, and one that represents the "total count", which
would appear in a second DataTable in your results DataSet.

Actually there are more sophisticated ways to handle paging, including some
that use new SQL Server 2005 features. You can find these on the web very
easily.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"JustinCarmony" wrote:
I'm using a DataAdapter to fill a DataSet to display a list of items
in a custom way. I'm not using the GridView or any server controls
like that.

This is my code:
<code>
SqlConnection sqlConn =
DatabaseControl.Database.GetConnection(Globals.dbC onn);
SqlCommand cmdTitles = new SqlCommand();
cmdTitles.CommandText = "SelectTitlesByCategory";
cmdTitles.CommandType = CommandType.StoredProcedure;

cmdTitles.Parameters.Add("@alpha", SqlDbType.VarChar, 25);
cmdTitles.Parameters["@alpha"].Value = alpha;

cmdTitles.Parameters.Add("@cat_id", SqlDbType.Int, 16);
cmdTitles.Parameters["@cat_id"].Value = cat_id;

cmdTitles.Connection = sqlConn;

DataSet dsTitles = new DataSet();
SqlDataAdapter adptTitles = new SqlDataAdapter(cmdTitles);

adptTitles.Fill(dsTitles, start, length, "titles");

</code>

Now this works great, but now for me to enable my paging, I need a way
to get a count of how many rows would have been retrieved if the
DataAdapter didn't limit the results. I want to avoid making a second
query, and I don't want to have to make a new stored procedure if
possible. Is there a way to acccomplish this?

Justin

Apr 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
4
by: Sondra Wilson | last post by:
I have created a sorted query. The total(records) I get in the query is correct. My problem lies with getting that total into my report. I use count to insert the total number of records in my...
4
by: Darryl Kerkeslager | last post by:
I'm trying to construct a simple query (Hah! then why can't I figure it out if it's so simple?) that totals the results where the drug test results are True, negative being treated like any other...
4
by: Tim T | last post by:
Hi, I have a stored procedure executing a search and an asp.net page displaying the results in a datagrid. The datagrid has paging on it, I am using Visual Studio.NET and can't see any option...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
4
by: Sean Shanny | last post by:
To all, Running into an out of memory error on our data warehouse server. This occurs only with our data from the 'September' section of a large fact table. The exact same query running over...
2
by: Rich | last post by:
Hello, Is there a way to capture the Records Affected count when performing a table Update on a Sql Server table using a DataAdapter? How is this done? Thanks, Rich
2
hodgeman
by: hodgeman | last post by:
My second thread on thescripts, so hoping to get the same feedback and help as last time... I've developed an online invoicing and payment system for all my accounts for my web design company....
1
by: jaxkookie | last post by:
I have been trying to count each answer for each question and roll this up to one line item per question with totals for each answer. what I am getting is staggered answers. example, question 1 has 9...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.