473,545 Members | 666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Total number of records paged gridview

Hi, I have a paged gridview (Apts_grd) tied to an Access DataSource
(Apts_srcGrd). How do I get the total number of data records returned
by the query?

The following shows only the number of records per page:

Apts_srcGrd.Sel ectCommand = "SELECT * FROM tblApts WHERE ..."
Apts_grd.DataBi nd()
Response.Write( "Count: " + Apts_grd.Rows.C ount.ToString

TIA, Mark

Aug 23 '06 #1
2 4598
-- Call ExecuteNonQuery to send command
int count = (int)cmd.Execut eScalar();

The query in the SqlCommand constructor obtains the count of all records
from a table. This query will only return a single value. The
ExecuteScalar method returns this value. Since the return type of
ExecuteScalar is type object, we use a cast operator to convert the value to
int.
Hope that helps
Patrick

<ms******@bluew in.chwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
Hi, I have a paged gridview (Apts_grd) tied to an Access DataSource
(Apts_srcGrd). How do I get the total number of data records returned
by the query?

The following shows only the number of records per page:

Apts_srcGrd.Sel ectCommand = "SELECT * FROM tblApts WHERE ..."
Apts_grd.DataBi nd()
Response.Write( "Count: " + Apts_grd.Rows.C ount.ToString

TIA, Mark

Aug 23 '06 #2
You can do that automatically,
you always need to count records on the DataSet itself

---------------------------------------
Sub BindSQL()
Dim MyConnection As SqlConnection
Dim DS as DataSet
Dim MyCommand As SqlDataAdapter
Dim RcdCount As Integer

'Our SQL string
Dim sqlStr As String = "SELECT titles.title, authors.au_lnam e, " & _
"authors.au_fna me, titles.price " & _
"FROM authors INNER JOIN titleauthor ON " & _
"authors.au _id = titleauthor.au_ id " & _
"INNER JOIN titles ON " & _
"titleauthor.ti tle_id = titles.title_id "

'The connection to our database
Dim strConn As String = "server=(local) ;uid=sa;pwd=;" & _
"database=pubs; Trusted_Connect ion=yes;"

'Open up our connection with our connection object
MyConnection = New SQLConnection(s trConn)

'To execute our Sql Statement and provide our active connection
MyCommand = NewSqlDataAdapt er(sqlStr, MyConnection)

'Create instance of DataSet object and fill our predetermined
'datagrid with it and we name it
DS = new DataSet()
MyCommand.Fill( DS, "pubs")

RcdCount = DS.Tables("pubs ").Rows.Count.T oString()

RecordCount.Tex t = "<b><font color=red>" & RcdCount & "</fontrecords
found"

Pubs.DataSource = DS
Pubs.Databind()

lblPageCount.Te xt = "Page " & Pubs.CurrentPag eIndex + 1 & " of " &
Pubs.PageCount
End Sub
---------------------------------------

you can see this link to have a better idea
http://www.developerfusion.co.uk/show/4060/2/
--

Bruno Alexandre
"a Portuguese in København, Danmark"


Aug 23 '06 #3

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

Similar topics

1
940
by: Steve | last post by:
I can't seem to find a property in the datagrid class that gives me the total number of records stored in it. Is there another way to do it?
2
7550
by: Ryan | last post by:
Access97 I hope someone out there can help. This is driving me crazy. Basically, I am trying to recreate VBA's built in navigation feature (The one that allows you to move first, next, previous, and last and also tells you that you are on Record # or . The navigation part was easy. My problem is determing the what record I am on and the...
1
2002
by: P | last post by:
Hello, I am having a difficult time updating a record via a stored procedure using the gridview and sqldatasource. I cannot seem to be able to find a way to set everything up so that I can pass the applicable fields in the gridview to a sqldatasource which in turn calls a sproc with the appropriate parameters and data. Any ideas? Thanks...
5
1768
by: Quentin Huo | last post by:
Hi: I want to retrieve a set of records from the query like: "SELECT * FROM tVisitors WHERE vTime>'1/1/2004'" And then I will put a part of records into a DataSet by: DataSet ds = new DataSet();
0
1434
by: tfsmag | last post by:
I know how to do summary footers in a gridview... but when i try it in a paged gridview it puts a footer on every page of just the items on that page. Any suggestions on how to get it to work so that it only posts on the last page of the gridview with the totals for the entire dataset? here is how i'm getting the footer summary now ...
5
10361
by: Smith | last post by:
Hi there, I am trying to get the total number of records when i am working on a form to write the VB code. But still, I have not found any function that shows it. Could anyone help? Thank you, Smith.
3
1982
by: renatois | last post by:
Line number on a GridView Hi all, I have some records on a GridView and I want to show a colunm wih the line number according to the order shown at the GridView. "One" for the first record, "two" for the second, "three" for the third and so on... it can't come from a field at the data base because it´s dinamic and depends on other fields. ...
2
1886
by: burger54 | last post by:
is there a simple way to attach the total number of records in a report to a text box on the report? I tried using the count function in the expression builder, but it returns the number 70 even thought there are only 2 records. I am using access 2000. Thanks in advance
2
1927
by: APEJMAN | last post by:
HI I am trying to find out the total number of recoreds in a Hash Table. I am trying to write a function to calculate the total number of the recored in the Hash Table here is what I figure out, but I am confused now ( my code in incomplete) would you please guid me? Thanks template <typename T,typename K> int...
0
7467
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
5971
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
703
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.