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

Home Posts Topics Members FAQ

how to know the number of records in a table?

I want to count the number of records in a table, and insert a new record
with ID increment the count by 1.

Heres the code:
sqlStmt = "SELECT COUNT(*) As numRecords FROM TimeSlot;"
cmd = New SqlCommand(sqlS tmt, conn)
dr = cmd.ExecuteRead er

But how to get the value of numRecords? since numRecords is not a field in
table TimeSlot

please help!
Nov 18 '05 #1
2 1111
You can't until u've read through all of them. The datareader is a forward
only read-only quick way to look at data.

If you need to know the number up front, use a dataset or datatable.

"Matthew Louden" <ma*******@hotm ail.com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
I want to count the number of records in a table, and insert a new record
with ID increment the count by 1.

Heres the code:
sqlStmt = "SELECT COUNT(*) As numRecords FROM TimeSlot;"
cmd = New SqlCommand(sqlS tmt, conn)
dr = cmd.ExecuteRead er

But how to get the value of numRecords? since numRecords is not a field in
table TimeSlot

please help!

Nov 18 '05 #2
RA
This won't work for multiple database connections. The incremeted count
might give you false information. I assume that the ID is unique value? If
yes then change it in the database to be an identity field. If you do that
let me know and I will help you on how to get the new row inserted.

Ronen

"Matthew Louden" <ma*******@hotm ail.com> wrote in message
news:#X******** ******@tk2msftn gp13.phx.gbl...
I want to count the number of records in a table, and insert a new record
with ID increment the count by 1.

Heres the code:
sqlStmt = "SELECT COUNT(*) As numRecords FROM TimeSlot;"
cmd = New SqlCommand(sqlS tmt, conn)
dr = cmd.ExecuteRead er

But how to get the value of numRecords? since numRecords is not a field in
table TimeSlot

please help!

Nov 18 '05 #3

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

Similar topics

1
2635
by: Bryan Zash | last post by:
When querying a bit field, I am encountering a problem with MS SQL Server returning a larger number of records for a table than the actual number of records that exist within that table. For example, my customer table has 1 million unique records, so the results of the following query are as such: select count(customer_nbr) from customer = 1,000,000 There is bit field in the customer table that denotes whether a
16
10114
by: usenet | last post by:
I want to be able to use the record numbers of a sub-form, are they available anyhow in VB (Access 2003)? I want to use the sub-form record number as *part* of the primary key for the table whose data is displayed on the sub-form. The other part of the primary key is the column used to join to the master table. E.g. I have TableA (the master table) with a primary key TableA.Column1. TableB which is shown in the sub-form has a primary...
2
1477
by: Vadim | last post by:
Hi! I imported some table (about 1500 records) using "LOAD DATA LOCAL INFILE..." (command line console). No warnings, no skipped, no deletes - all the recored are written to be imported. However, in MySQL Administrator UI tool I see completely different number in the "Rows" column. Making a SELECT query shows that the actual number of records in the table is the correct one (the same number as in text file table). Command line SHOW TABLE...
8
3998
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006 10:00:00 AM 12:00:00 PM 120
5
3820
by: slickdock | last post by:
I need to break my query into 3 groups: First 60 records (records 1-60) Next 60 records (records 61-121) Next 60 records (records 122-182) Of course I could use top values 60 for the first query, but where do I go from there?
0
8427
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8850
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8523
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8626
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1737
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.