Click here to Skip to main content
15,885,760 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi there,

i have a table with data in Ms Access like....

CountryName Medal

India        Gold
USA        Silver
China        Gold
India        Gold
India        Gold
USA        Bronze
India        Silver
USA        Gold
USA        Silver
India        Bronze

now my question is , i want this table data in gridview like......

country      Gold      Silver      Bronze
India               3         1            1
USA                1         2            1
China              1         0             0


thanks
Posted
Updated 20-Sep-12 16:09pm
v2
Comments
[no name] 20-Sep-12 7:33am    
Okay good for you. Please come back when you have a question to ask.

Permission granted! Please, proceed.

Or did you have a question in there noboday can find?? What part of this are you having a problem with?

Nobody is just going to give you code. This little assignment reeks of being homework and we're not here to do your homework for you so you can pass a class that you don't deserve to pass.
 
Share this answer
 
Comments
Aniruddh Bhatt 20-Sep-12 7:53am    
i am only able to do this code i want only idea not full code.how can i count medals state wise and only print one state one time.

ss = "Select * from winner"
com = New OleDbCommand(ss, con)
con.Open()
dr = com.ExecuteReader
While dr.Read()
i = DataGridView1.Rows.Add(+1)
If dr(1) = "Gold" Then
g = g + 1
ElseIf dr(1) = "Silver" Then
s = s + 1
ElseIf dr(1) = "Bronze" Then
b = b + 1
End If

DataGridView1.Rows(i).Cells(1).Value = dr(0)
DataGridView1.Rows(i).Cells(2).Value = g
DataGridView1.Rows(i).Cells(3).Value = s
DataGridView1.Rows(i).Cells(4).Value = b
End While
con.Close()
Dave Kreskowiak 20-Sep-12 12:51pm    
Doesn't the layout of your result table above suggest that you would need a two dimensional array to hold this data?? Or at least a collection of objects that holds a country name and 3 values??

No, I'm not going to write your code for you.
Dave Kreskowiak 24-Sep-12 0:51am    
I know that. But I'm also not going to give him the answer to his homework assignment.
Hi
I just generated the sql query which yeilds the required result.

SQL
SELECT Name,
       (SELECT COUNT(medal)
          FROM  [TantraCAD].[dbo].[Sample] as Sample_1  Where Medal = 'Gold' and Sample_1.Name = Simplu.Name) AS "Gold",
          (SELECT COUNT(medal)
          FROM  [TantraCAD].[dbo].[Sample] as Sample_1 Where Medal = 'Silver' and Sample_1.Name = Simplu.Name) AS "Silver",
          (SELECT COUNT(medal)
          FROM  [TantraCAD].[dbo].[Sample] as Sample_1 Where Medal = 'Bronze' and Sample_1.Name = Simplu.Name) AS "Bronze"
  FROM [TantraCAD].[dbo].[Sample]
GROUP BY
  Name


Where sample is the table name try this and let me know.

Happy coding...
 
Share this answer
 
Comments
Aniruddh Bhatt 21-Sep-12 23:10pm    
dear i don't have a knowledge of C#. i am using vb.net.
thanks
BheemG 24-Sep-12 0:05am    
this is sql query not c# use this sql query to fetch the required output from your ms access datatbase.
use sql query

select count(Columnname) from table group by (columnname)
 
Share this answer
 
Comments
Aniruddh Bhatt 25-Sep-12 1:02am    
not working
xErvender 25-Sep-12 1:22am    
select count(*),Medal from table group by medal

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