By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

how to count records and display a field.

P: 1
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
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,382
Your query doesn't return empid.
May 21 '13 #2

Post your reply

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