how to get a data from database to grid if table is in this format [Resolved]

Posted by Raghu16 under ASP.NET on 4/25/2012 | Points: 10 | Views : 1201 | Status : [Member] | Replies : 1
Hi all,

I have two tables

1.Country
2.Country2

In Country have certain fields like

1.CountryID (PK)
2.Country
3.Capital
4. Continent


In Country2 i have

1.CountryID (FK)
2.ID (PK)
3.country flag
4. country currency


Sample date inside Country

CountryID Country Capital Continent
C1 India Delhi Asia
C2 XXX XXXX XXXX
C3 YYYY YYYY YYYY


Sample data in Country 2
ID CountryID country flag country currency
1 C1 Indiaflag Rupee
2 C2 XXXXflag XXXX
3 C3 YYYYflag YYYY

I need to get Data in Dataset or DataTable like below

CountryID Country Capital Continent country flag country currency
C1 India Delhi Asia indiaflag Rupee
C2 XXX XXXX XXXX XXXXflag XXXX
C2 YYYY YYYY YYYY YYYYflag YYYY




Responses

Posted by: Raghu16 on: 4/27/2012 [Member] Starter | Points: 25

Up
0
Down

Resolved
1. Create the connection class
2. Create the command class as
SqlCommand cmd= new SqlCommand("C.CountryID, C.Country, C.Capital, C.Continent, C2.[country flag], C2.[country currency] From Country C, Country2 C2 Where C.CountryId= C2.CountryId");
DataSet ds= new DataSet();
SqlDataAdapter da= new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource= ds;
GridView1.DataBind();

Raghu16, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response