Ways to get single value or aggregates from db 
Author Message
 Ways to get single value or aggregates from db

I am newbie on VB, just moved from Access VBA up to VB6 and SQL server. In
Access or Access ADP, we have DLookup, DCount, Dmax... those handy built-in
functions to get a single value in VB from database. Say, a table in SQL
Server with two columns: File_ID, File_Name.

How can I get the File_Name for File_ID = 3? or the current maximum File_ID?

I know how to deal with recordsets in VB code, but those simple stuff
(single value retrieval) stuck me. Help Please.
Shao



Mon, 15 Sep 2003 01:08:10 GMT  
 Ways to get single value or aggregates from db
There's not really a parallel in VB6/SQL Server, but you can do the same
thing with simple SQL statements:

DLookup:
    SELECT File_Name FROM Some_Table WHERE File_ID = 3
DCount:
    SELECT Count(File_Name) FROM Some_Table [WHERE File_ID = 3]
    'Counts non-null File_Name entries
or
    SELECT Count(*) FROM Some_Table [WHERE File_ID = 3]
    'Counts records
DMax:
    SELECT Max(File_Name) FROM Some_Table [WHERE File_ID = 3]

Learn the Structured Query Language (SQL) and database normalization
principles and techniques (if you don't already), and learn to create your
own ADO recordsets in code.  Do not get used to the data control(s) - they
will get you in trouble at some point!

Good Luck and HTH,
Tore.


Quote:
> I am newbie on VB, just moved from Access VBA up to VB6 and SQL server. In
> Access or Access ADP, we have DLookup, DCount, Dmax... those handy
built-in
> functions to get a single value in VB from database. Say, a table in SQL
> Server with two columns: File_ID, File_Name.

> How can I get the File_Name for File_ID = 3? or the current maximum
File_ID?

> I know how to deal with recordsets in VB code, but those simple stuff
> (single value retrieval) stuck me. Help Please.
> Shao



Wed, 17 Sep 2003 08:08:56 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Getting a single value

2. Getting a single char, Putting a single char.

3. Getting memo values from DB into VB5?

4. Need more DB connectivity ways

5. Aggregate function for values of fields in record

6. Warning, null value eliminated from aggregate

7. Warning, null value eliminated from aggregate

8. Obtaining the Value of the SQL aggregate function

9. Getting Errors when Access DB gets large

10. getting R G B values from a long value

11. Getting a single character from the modem

12. Getting a single line out of a Variant (<=-- or something like that)

 

 
Powered by phpBB® Forum Software