|
| Re: RecordCount in VB ASP.NET? |
 |
Mon, 24 Mar 2008 18:34:55 +000 |
It depends on when you need the count. If it's after iterating the DataReader,
you could declare an int, and increment it each time the While DataReader.Read()
loop runs. If before that point, you need to use a DataSet instead. A
DataReader has no idea of the numbers of records, because it is effectively just
a dumb pipe into the database that spews out whatever records the SQL generates
one at a time.
|
| Post Reply
|
| Re: RecordCount in VB ASP.NET? |
 |
Mon, 24 Mar 2008 19:13:51 +000 |
It doesn't matter to me when the count is done. It just needs to be displayed
on the page when done.
Should I be using a different method for displaying this query than using
DataReader? I want to display results in a table on the browser, but I don't
want all fields from the DB to show. I need to be able to choose which fields
display.
|
| Post Reply
|
| RecordCount in VB ASP.NET? |
 |
Mon, 24 Mar 2008 20:05:00 +000 |
Is there a RecordCount for asp.net? I'm new to .net and I'm not quite sure how
to get a record count for the following code. I'm guessing that I should maybe
have a variable in between the repeater controls that increments, or maybe there
is some special code that could work from the script tags in the page head? The
database is Access, and I'm using VB. I simply want a count of all records
resulting from the query.
------------------------------------------
<%@ Page Explicit="True" Language="VB"
Debug="True" %>
<html>
<head>
<title>Test Table</title>
<script runat="server">
Sub Page_Load
Dim dbconn, sql, dbcomm, dbread
dbconn = New
Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
source=" & Server.MapPath("testCust.mdb"))
dbconn.Open()
Dim DtToday
DtToday = "#" & Date.Today & "#"
Label1.Text = Date.Today
sql = "SELECT * FROM tblNames WHERE DateAdd=" & DtToday
Label2.Text = sql
dbcomm = New Data.OleDb.OleDbCommand(sql, dbconn)
dbread = dbcomm.ExecuteReader()
customers.DataSource = dbread
customers.DataBind()
dbread.Close()
dbconn.Close()
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:Label ID="Label1"
runat="server"></asp:Label><br />
<asp:Label ID="Label2"
runat="server"></asp:Label>
<asp:Repeater id="customers" runat="server">
<HeaderTemplate>
<table border="0" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%#Container.DataItem("RecordID")%></td>
<td><%#Container.DataItem("FName")%></td>
<td><%#Container.DataItem("LName")%></td>
<td><%#Container.DataItem("DateAdd").ToShortDateString%>&l
t;/td>
<td><%#Container.DataItem("TimeAdd")%></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</form>
</body>
</html>
|
| Post Reply
|
| Re: RecordCount in VB ASP.NET? |
 |
Mon, 24 Mar 2008 20:25:14 +000 |
I give up. Everything I try errors. I really don't understand how to use
Repeater.Items.Count, and I don't understand what you mean by "If it's
after iterating the DataReader, you could declare an int, and increment it each
time the While DataReader.Read() loop runs." because I don't see a While
DataReader.Read() loop. I'm lost.
Compiler Error Message: BC30469: Reference to a non-shared member requires an
object reference.
Source Error:
Line 43: dbcomm = New Data.OleDb.OleDbCommand(sql, dbconn)
Line 44: dbread = dbcomm.ExecuteReader()
Line 45: RecCount = Repeater.Items.Count()
Line 46: Label2.Text = RecCount
Line 47: customers.DataSource = dbread
|
| Post Reply
|
| Re: RecordCount in VB ASP.NET? |
 |
Mon, 24 Mar 2008 20:35:05 +000 |
Something like dbread.count within the PageLoad event should work.
|
| Post Reply
|
|
|
|
|
|
|
|
|
|