keyongtech


  keyongtech > dotnet.framework.aspnet.* > dotnet.framework.aspnet.main > 08/2006

 #1  
08-23-06, 07:08 AM
msch-prv
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.SelectCommand = "SELECT * FROM tblApts WHERE ..."
Apts_grd.DataBind()
Response.Write("Count: " + Apts_grd.Rows.Count.ToString

TIA, Mark
 #2  
08-23-06, 08:27 AM
Patrick.O.Ige
-- Call ExecuteNonQuery to send command
int count = (int)cmd.ExecuteScalar();

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

<msch-prv> wrote in message
news:7760
[..]
 #3  
08-23-06, 08:41 AM
Bruno Alexandre
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_lname, " & _
"authors.au_fname, titles.price " & _
"FROM authors INNER JOIN titleauthor ON " & _
"authors.au_id = titleauthor.au_id " & _
"INNER JOIN titles ON " & _
"titleauthor.title_id = titles.title_id"

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

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

'To execute our Sql Statement and provide our active connection
MyCommand = NewSqlDataAdapter(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.ToString()

RecordCount.Text = "<b><font color=red>" & RcdCount & "</font> records
found"

Pubs.DataSource = DS
Pubs.Databind()

lblPageCount.Text = "Page " & Pubs.CurrentPageIndex + 1 & " of " &
Pubs.PageCount
End Sub
---------------------------------------

you can see this link to have a better idea
http://www.developerfusion.co.uk/show/4060/2/
Similar Threads
using total number of records for random number

Hello, I am trying to figure out a way to select one record at random out of almost 400,000 records. I decided the easiest way would be to select a random number using...

Getting total number of records

Hi. I Need to get the number of records from a table not referenced in the form where the total is supposed to show but from another form. I suppose I can get the value...

total number of records

I have a query that is pulling records based on sales rep and date. The total number of records determines a commission tier. I have the both tables in my query (sales info...

GridView: Total Records Count

I need to get the total number of items/records returned into GridView. If I just do myGridView.Rows.Count, then it just returns me the total number of items on the...

GridView: Total Records

I need to get the total number of items/records returned into GridView. If I just do myGridView.Rows.Count, then it just returns me the total number of items on the...


All times are GMT. The time now is 03:30 PM. | Privacy Policy