Hello World
I know how to display or manipulate (add,delete,update,search) records using the OleDbDataReader and OleDbCommand class. But I'm clueless in getting the total record on a query.
In vb6, I know how to do it by using recordset.recordcount. I've just tried using DataTable and OleDbDataAdapter class but I can't make it. Please guide me. BTW, I'm using vb2005.
Rey Sean
8 7279
A quick answer would be to modify your query slightly to contain a count of the records. -
-
sql = "SELECT COUNT(column) as MyCount, * FROM MyTable"
-
-
DBReader.Read()
-
-
NumberOfReceords = DBReader("MyCount")
-
-
DBReader.Close
-
I am probably missing a better way, but I too am accustomed to using ADODB recordsets in classic asp.
That said though, this will work.
A quick answer would be to modify your query slightly to contain a count of the records. -
-
sql = "SELECT COUNT(column) as MyCount, * FROM MyTable"
-
-
DBReader.Read()
-
-
NumberOfReceords = DBReader("MyCount")
-
-
DBReader.Close
-
I am probably missing a better way, but I too am accustomed to using ADODB recordsets in classic asp.
That said though, this will work.
It gives me an error result .
OK.
Can I see what your code looks like ?
You wouldnt be able to copy and paste mine directly and expect it to work obviously.....it was just an example.
-
Private adDataReader As OleDbDataReader
-
Private adCommand As New OleDbCommand
-
-
Friend Function GetTotalItem() As Integer
-
Call Main.SetConnection()
-
-
adCommand = New OleDbCommand("Select Count(ScheduleID) As myCount, * From Schedules", dbConnection)
-
adCommand.CommandType = CommandType.Text
-
adDataReader = adCommand.ExecuteReader
-
adDataReader.Read()
-
-
-
GetTotalItem = adDataReader("myCount")
-
-
adDataReader.Close()
-
Main.CloseConnection()
-
End Function
Rey Sean
Ok. It would also help to know what the actual error is.
Off hand you could try this in case your query is not pulling anything -
-
Private adDataReader As OleDbDataReader
-
Private adCommand As New OleDbCommand
-
-
Friend Function GetTotalItem() As Integer
-
Call Main.SetConnection()
-
-
adCommand = New OleDbCommand("Select Count(ScheduleID) As myCount, * From Schedules", dbConnection)
-
adCommand.CommandType = CommandType.Text
-
adDataReader = adCommand.ExecuteReader
-
-
-
if adDataReader.Read() then
-
GetTotalItem = adDataReader("myCount")
-
else
-
GetTotalItem = 0
-
end if
-
adDataReader.Close()
-
Main.CloseConnection()
-
End Function
-
-
-
Sorry for the late reply. Even with or without if-else statement, it always returns 0.
Rey Sean
Hi Ray,
Instead of DataReader , Use a Combination of DataAdapter,DataSet,DataTable..
Check this code: -
Dim OConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\MyDb.mdb;")
-
OConn.Open()
-
Dim sSQL As String = "Select * From MyTable"
-
Dim ODa As New OleDbDataAdapter(sSQL, OConn)
-
Dim DS As New DataSet
-
Oda.Fill(DS)
-
Dim DT As DataTable = DS.Tables(0)
-
Dim RecCnt As Integer = DT.Rows.Count
-
OConn.Close
-
To jeffstl,
adCommand = New OleDbCommand("Select Count(ScheduleID) As myCount, * From Schedules", dbConnection)
Problem with the SQL Statement, using aggregrate function Count without Grouping Results in an Error..
Regards
Veena
Thanks veena.. I'll try this later : )
Rey Sean
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rick |
last post by:
I want to get a resultset of every table in the database, with the
current record count of each. What is the easiest way to do this?
I can get the list of tables with:
Select s.name from...
|
by: 6thirty |
last post by:
Hi,
I've created a stocktaking database using Access XP. This is indexed by two
fields - part number and shelf location.
I am currently inputting all the data via a form. When I have entered a...
|
by: Greg Smith |
last post by:
I am trying to write a SQL query that will return a record count to my C#
application. I wrote the following query:
ALTER PROCEDURE up_justification_duplicate
AS
SELECT COUNT(*)
FROM...
|
by: darrel |
last post by:
I'm trying to whip up a fancy repeater control that will put records into a
two-column table for me.
This is how I envision it working:
itemtemplate
if record count = odd then write out the...
|
by: darrel |
last post by:
I have a repeater that I'd like to apply some logic to, namly highlighting
the top few items in the repeater. To do this, I need to determine the
record count.
I've tried this:
<%
dim...
|
by: Peter W Johnson |
last post by:
Hi guys,
I have a problem with a datagrid record count. Here is the code:-
<snip>
Public Class frmMerchantDeposit
Inherits System.Windows.Forms.Form
Dim myconnection As New...
|
by: noLoveLusT |
last post by:
hi everyone i am very very new to the sql server (2 days actually and ) so
far i learned creating SPs etc but couldnt workout how to get return value
from my prodecure
my sp as follows...
|
by: Pramod Kadur |
last post by:
Using borland c++, how can we fetch the record count in the following case:
Suppose in XY table in Foxpro,
First column
A
B
C
D
E
F
|
by: bushi |
last post by:
hi !
i have following code to display some text on a web form,after
getting it from database.
<asp:DataList ID="DataList1" runat="server"
DataSourceID="SqlDataSource1">
<ItemTemplate>...
|
by: sparks |
last post by:
I have always just got a count on records and put up a box at the top
of the entry forms saying something like 1 of 500 and updating it as
you got to 500 of 500.
I have never thought of this as...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |