Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
student table as follows

studid studname minorcode

1 Ram AFF
2 Suresh MFA
3 Vignesh CTF
4 Sunil ROC


course table as follows
Courseid minorcode Amt Paymentmode

1 AFF 5000 Cash
2 MFA 8000 Cash
3 CTF 12000 Cash
4 ROC 16000 Cash




Code as follows in Show Button


string minorcode;
sql = "select s.studname,s.minorcode,c.Amt,c.Paymentmode from studnet s,course c where s.minorcode = c.minorcode
dr = scon.ReadSql(sql);
while (dr.Read())
{
minorcode = dr[0].ToString().Trim();
sql = "Select Amt from course where minorcode = '" + minorcode.ToString().Trim() + "'";
dr1 = scon.ReadSql(sql);
while (dr1.Read())
{
GridView.DataSource = dr;
GridView.DataBind();
GridView.Visible = true;
}
}

from the above coding i want to show the data in gridview as follows


in my above code i am using two datareader(dr) dr and dr1. but i want to show the two datareader values shown in one GridView

for GridView i written the code as above (GridView.DataSource = dr;)

how can i display two datareader values in one Gridview.

i want the output as follows in Gridview;

studname minorcode Amt Paymentmode

Ram AFF 5000 Cash
Suresh MFA 8000 Cash
Vignesh CTF 12000 Cash
Sunil ROC 16000 Cash


please help me.

whether my code is correct.i tried but in gridview above output is not displaying.

Regards,
Narasiman P.
Posted
Comments
Ezra Neil 15-May-13 10:07am    
If you have to do it in two query, why don't you just create your own datatable/dataset and just insert the required data into it?

1 solution

Use stored procedures .. get combined result from it
 
Share this answer
 
Comments
Mahesh Bailwal 15-May-13 10:47am    
I don't think it’s possible to show the two datareader values in one gridview. You can go for other alternates for achieving the same. Below are my suggestions

1. Create inner join on two tables and get data in one datareader
2. Create datatable (in .Net) for both the datareaders and create relation on them to get desired data.
3. Create dynamic HTML table to show data of two datareaders.

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