Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Can we use aggregate functions on data set. For example, I have data of 10 subjects with each subject having more than 200 students data. Want to get subject wise number of students who scored more than 50 marks.

Something like

SQL
Select subject,count(*) from data_set("table1") where marks >=50 group by subject order by subject.

and result will be something like

C#
SUBJECT-1   20
SUBJECT-2   30
SUBJECT-3   44


and so on.

Can anyone give me similar syntax which works on data set?

Anand
Posted
Updated 23-Aug-13 20:22pm
v4

1 solution

Belowing Code will help you......


Dim connection As SqlConnection = New sqlconnection()
connection.ConnectionString = "Your Connection String"
connection.Open()
Dim adp As SqlDataAdapter = New SqlDataAdapter("Select subject,count(*) from data_set("table1") where marks >=50 group by subject order by subject", connection)
Dim ds As DataSet = New DataSet()
adp.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
 
Share this answer
 
Comments
Anand Rangaraju 24-Aug-13 8:44am    
Thanks Mr.Rakesh for the reply. But, I guess you did not understand the question properly or I did not present properly. I will elaborate more on this.

After the data is acquired in the data set
wsql_query = "SELECT sub_code,marks from marks_table order by sub_code"
da = New OleDbDataAdapter(wsql_query, con)
ds = New DataSet
da.Fill(ds, "student_data")
Now, I want to run a query from the ds.tables("student_data") as below
SELECT SUB_CODE,COUNT(*) FROM DS.TABLES("STUDENT_DATA") WHERE MARKS>50 GROUP BY SUB_CODE

Hope I made it clear now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900