Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 20-Sep-12 1:26am
Edited 20-Sep-12 16:09pm
v2
Comments
Wes Aday at 20-Sep-12 7:33am
   
Okay good for you. Please come back when you have a question to ask.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Aniruddh Bhatt at 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 at 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 at 24-Sep-12 0:51am
   
I know that. But I'm also not going to give him the answer to his homework assignment.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi
 
I just generated the sql query which yeilds the required result.
 
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...
  Permalink  
Comments
Aniruddh Bhatt at 21-Sep-12 23:10pm
   
dear i don't have a knowledge of C#. i am using vb.net. thanks
BheemG at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

use sql query
 
select count(Columnname) from table group by (columnname)
  Permalink  
Comments
Aniruddh Bhatt at 25-Sep-12 1:02am
   
not working
Ervin Pacibe at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 498
2 Tadit Dash 420
3 sanket saxena 337
4 Zoltán Zörgő 230
0 Sergey Alexandrovich Kryukov 11,800
1 OriginalGriff 7,225
2 Peter Leow 5,009
3 Abhinav S 3,893
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 24 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid