Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
student table

Studid    Bfid   Rate

  A        1      Good
  B        2      Fair
  C        3      Excellent

Batch table
Bfid     Class

   1        EFA
   2        MFA
   3        COC

Code as follows;
C#
sql = "Select studid,Bfid,Rate from student";
dr = scon.readsql(sql);
while(dr.read())
{
     bfid = dr[0].tostring().trim();
     sql = "select Class from batch";
     dr = scon.readsql(sql);
     if(d.hashrows == true)
     {
         gridview.datasource = dr;
         GridView1.DataBind();
         GridView1.Visible = true;
     }

In run mode as follows

I have one button called Load when i click that button the output as follows in gridview
Studid  Bfid    Rate       class

   A     1     Good        EFA
   B     2     Fair        MFA
   C     3     Excellent   COC

for that how can i do using csharp.

Regards,
Narasiman P.
Posted
Updated 10-May-13 2:51am
v2

Just change your sql statement to
C#
sql = "Select studid,s.Bfid,Rate,class from student s left outer join Batch b on s.Bfid=b.Bfid";

I've used left outer join in case you have student records that do not have Batch records. If you only want to list students that do have a Batch record then change it to inner join
Also note that I've had to specify s.Bfid in the select clause because the column Bfid appears on both tables. Just using Bfid leads to an ambiguity error.
 
Share this answer
 
try with single query ...
C#
sql = "Select studid,Bfid,Rate,Class from student,batch";

after this bind grid
 
Share this answer
 

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