Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Help pls


Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2006, 01:48 AM
thevision thevision is offline
Freshman
 
Join Date: Jan 2006
Posts: 44
Default Help pls


i am using ADO and how do i find out how many records is in the table?

let's say a table name fruits and i was searching using SQL

SELECT * FROM Fruits WHERE FruitName = "Apple"

there was 10 apples inside the fruits table, how do i know from the coding?
Reply With Quote
  #2  
Old 02-08-2006, 02:03 AM
anthony_n's Avatar
anthony_n anthony_n is offline
Senior Contributor
 
Join Date: May 2005
Location: Manchester,England
Posts: 1,293
Default

just run a query
Select count(*) from fruits where FruitName = "Apple"

what type of database is this?
__________________
ADO TUTOR

File IO Tutor
Reply With Quote
  #3  
Old 02-08-2006, 02:25 AM
thevision thevision is offline
Freshman
 
Join Date: Jan 2006
Posts: 44
Default

i am using access. how to store the count(*) into a variable?

hmm... i heard that can use recordset to store the number of record affected and i had go through msdn but couldn't understand it... can show me some code??
Reply With Quote
  #4  
Old 02-08-2006, 03:11 AM
MilanJ MilanJ is offline
Junior Contributor
 
Join Date: Sep 2005
Posts: 370
Default

Such:
"select count(*) as Numb .... "
And then you can Numb store to a variable.
Reply With Quote
  #5  
Old 02-08-2006, 03:29 AM
thevision thevision is offline
Freshman
 
Join Date: Jan 2006
Posts: 44
Default

hmm... i get 0 instead of 10

here is my example of my code:
Code:
'general Dim db As ADODB.Connection Dim em, si As ADODB.Recordset 'em for employee, si for system info 'formload Set db = New ADODB.Connection db.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=test" db.Open 'search function Dim searchfruit As ADODB.Recordset set searchfruit = new adodb.recordset searchfruit.open "SELECT COUNT(*) as total FROM Fruits Where FruitsName = '" & txtfruit.text & "'" msgbox total,,"test"

how?
Reply With Quote
  #6  
Old 02-08-2006, 03:37 AM
MilanJ MilanJ is offline
Junior Contributor
 
Join Date: Sep 2005
Posts: 370
Default

If it selected wrong number, then your condition may be wrong - check the content of your txtfruit.text, if it is adequate.
You can also launch such select statement from Access, what would be the result.
MilanJ
Reply With Quote
  #7  
Old 02-08-2006, 03:39 AM
thevision thevision is offline
Freshman
 
Join Date: Jan 2006
Posts: 44
Default

no, even i change the txtfruits.text to apple it still returns me 0
and i don't know how to launch statement from access
Reply With Quote
  #8  
Old 02-08-2006, 03:53 AM
MilanJ MilanJ is offline
Junior Contributor
 
Join Date: Sep 2005
Posts: 370
Default

Well, try select without any selecting criteria, it will return numer of all records in the table:
"SELECT COUNT(*) as total FROM Fruits"
EDIT: Now I noticed your MsgBox in the code. You need there make reference between selected row and recordset - fro example such:
msgbox searchfruit!total,,"test"

Last edited by MilanJ; 02-08-2006 at 04:03 AM.
Reply With Quote
  #9  
Old 02-08-2006, 03:56 AM
thevision thevision is offline
Freshman
 
Join Date: Jan 2006
Posts: 44
Default

return as nothing... not even 0 and how to import query from access?
Reply With Quote
  #10  
Old 02-08-2006, 04:00 AM
MilanJ MilanJ is offline
Junior Contributor
 
Join Date: Sep 2005
Posts: 370
Default

Quote:
Originally Posted by thevision
return as nothing... not even 0 and how to import query from access?
I replied in EDIT in my previous post - you need make reference between recordset and selected row - msgbox searchfruit!total
Reply With Quote
  #11  
Old 02-08-2006, 05:40 AM
thevision thevision is offline
Freshman
 
Join Date: Jan 2006
Posts: 44
Default

Yeah ! it works ! thanks ^^
Reply With Quote
  #12  
Old 02-08-2006, 08:41 AM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

Also, note that with VB6, your statement
Code:
Dim em, si As ADODB.Recordset 'em for employee, si for system info
defines em as a variant, and only si is defined as an ado recordset... You need to EXPLICITLY dim them both if you wish to have TWO ado recordsets. Like this:
Code:
Dim em As ADODB.Recordset, si As ADODB.Recordset 'em for employee, si for system info
(or, place the declarations on separate lines...)
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->