473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to count records and display a field.

Please help me solve my problem.

I'm making a program that counts the number of records in my database.

Expand|Select|Wrap|Line Numbers
  1. SqlQuery = "SELECT COUNT(*) FROM emp_tbl WHERE lname LIKE '%" & txtSearch.Text & "%' or fname LIKE '%" & txtSearch.Text & "%' "
  2.  
  3.  
  4. With SqlCommand
  5.     .CommandText = SqlQuery
  6.     .Connection = sConnection
  7.     .ExecuteNonQuery()
  8. End With
  9. dim temp = SqlCommand.ExecuteReader()
  10. If temp.Read = False Then
  11.     MsgBox("Name not found.")
  12.     temp.Close()
  13. Else
  14.     id = temp("empid")
  15.     count = temp.GetValue(0)
  16.     MsgBox("There is only " & count & " ID number matching your search." & id)
  17.     temp.Close()
  18. End If
if the txtSearch matches only one record then a message box would pop out and display the id number of the matching record.

so far I was only able to display the number of record but I would get an error in displaying the id number.
May 21 '13 #1
1 1486
Rabbit
12,516 Expert Mod 8TB
Your query doesn't return empid.
May 21 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Melissa | last post by:
I have a sales report where the sales are grouped by district. The report is based on a query with criteria for sales date to get the sales in any specified date range. I have code in the Format...
4
by: alltechsolutions.net | last post by:
Been at this for two days now... I have a customer database with various fields, two of which are: ContactID (an autonumber field) & ReferralID (long Integer) When a customer refers someone...
2
by: Pete | last post by:
I need to create a single query (Not a SQL query) against a single table that counts the number of records in the table, where the single field "tmp" contains specific string values If the field...
6
by: drazenj | last post by:
Hi , sorry for my english ... I work in high school as a teacher and try to make CLASS SCHEDULE (TIME schedule) for my collegues and for students . My problem is that I don't know how to...
5
by: Soccer5 | last post by:
Trying to Count records on a report that meet a certain criteria. Have a text box in the Report Footer that has the following in the Control Source: =Count(="S") This does not work. It...
0
by: Sharon V | last post by:
This is driving me crazy - my unmatched query wizard will not display field names for any tables I choose. All my other query wizards work properly. I am running Access 2003. I have tried using...
10
by: sunsom | last post by:
i want to change the display field to a drop down when a check box is clicked.
7
by: iahamed via WebmasterKB.com | last post by:
Hi all, I need to display records Horizontally, I do not know for some reason this code gives me an error, uses an access db. Microsoft VBScript compilation (0x800A040E) 'loop' without 'do'...
1
Jerry Maiapu
by: Jerry Maiapu | last post by:
Hi there please can someone tell me how to create a query that will group a particular field and count the records in that field and return itsrecord with the maximum count.. The fields are in a...
5
by: phill86 | last post by:
Hi I want to be able to count records in a dao.querydef recordset but I keep getting the error message method or data member not found I have also tried to find out if the recordset is at...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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,...
0
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...
0
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,...
0
jinu1996
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...
0
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...
0
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...
0
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,...

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.