how to count attibutes from database

izza_azhar

Member
Joined
Mar 1, 2006
Messages
17
Programming Experience
Beginner
hi everyone..i'm newbie in vb..net actually.
my problem is like this..

1.for example i want to query from db
**select distinct (course) from student- example output are engineering, IT, pharmachist, communication, etc..(about 15)

2. how i can count total student taking each course
**select count(course) from STUDENT_TABLE where couse = 'IT'
-assume that we didnt know COURSE information
-IT course - we might put to the variable rite?

3.i have to use the loop rite? can anyone show me how to solve this problem??

thanks~~~
 
You are right on track.
Think about 2 seperate datasets. Dataset1 - Table1 will use the 'DISTINCT' select statement, Dataset2 - Table2 will Query the same table based on the COURSE value of Table1.
If you Display Table1 in a grid, A button_click or Double_Click would set the COURSE value of the grid to the parameter for the Table2 query and execute the query.

To get the number of students for each course you just need to know how many records your query returns.
Me.BindingContext(DataSet21, "Table2").Count


Incidently, this application could be displayed and handled nicely with a crystal report. One query of all records of the Students table could be grouped by COURSE and set up to display a Sum total of record counts for each group.
I answered a question about limiting the number of records per page in Crystal Reports somewhere in this forum. It explains how to set up a record count parameter.

Hope this helps.


 
Back
Top