2

I have two queries which are specified below.

select (t1.projectID),t2.FID,t1.Title,t1.ConsultancyAgency,t1.Client 
from (select * from consultancy_det ) t1 
inner join (select * from contribution_fid_map) t2 on t1.ProjectID = t2.ProjectID

Second Query is:

select name,fid from Personal_det;ss

Output of First Query

ProjectID      FID               Title                                         ConsulancyAgency    Client
   1         mahe001508     Android Application Development Project Ideas       MAHE               ICAS
   1         7894           Android Application Development Project Ideas       MAHE               ICAS
   2         2222                     abc                                       MIT                KMC
   2         7894                     abc                                       MIT                KMC

Output of second query:

  Name        FID   
 abcgh        2222
 ANaa         7894
 hhk          faw1
Shreyas Tg  mahe001508
NewFaculty  mcis001

Now using those above query i need to bind the data to the Gridview in asp.net and the gridview should be seen some what like this.

ProjectID     FID              Title                                         ConsulancyAgency  Client
   1         Shreyas Tg     Android Application Development Project Ideas      MAHE             ICAS
             ANaa                                                                        
   2         abcgh              abc                                            KMC               MIT                
             ANaa     

Is this possible to display the data like this in gridview?? Any help appreciated.

1 Answer 1

1

If I understand what you're asking, you want the FID and Name columns from Both subqueries to be bound to the GridView?

First you'll need to alias the columns:

select
    q1_FID = q1.FID,
    q1_Name = q1.Name,
    q2_FID = q2.FID,
    q2_Name = q2.Name,
    other_columns
from
(
   select fid, name, projectID from yourTable
) as q1
inner join
  yourOtherTable q2 on q2.projectID = q1.projectID

Then you just name the columns aliases in your Column set up for the GridView

<asp:GridView ID="yourGV" runat="server">
    <Columns>
       <asp:BoundField DataField="q1_FID" HeaderText="First FID"/>
       <asp:BoundField DataField="q1_Name" HeaderText="First Name"/>
       <asp:BoundField DataField="q2_FID" HeaderText="Second FID"/>
       <asp:BoundField DataField="q2_Name" HeaderText="Second Name"/>
    </Columns>
</asp:GridView>

EDIT

Updated SQL query:

select
name, t1_fid, q.projectID, pd.fid, title, consultancyAgency, client
from
personal_det pd 
inner join
(
select (t1.projectID),t2.FID,t1.Title,t1.ConsultancyAgency,t1.Client 
from (select * from consultancy_det ) t1 
inner join (select * from contribution_fid_map) t2 on t1.ProjectID = t2.ProjectID
) as q on q.fid = pd.fid
Sign up to request clarification or add additional context in comments.

1 Comment

Actually i need Name instead of FID in the ouput where in FID is FK constraint for two tables Contribution_FID_Map and personal_det but Name is not present in Contribution_FID_Map

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.