Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have to join fields from three table.
could you please correct

string selectcmd = " SELECT a.DoDate,a.DoNumber,a.CusId,b.CompName,b.CompAddress,b.Tel,b.Fax,b.ContPerson,b.SalesPerson,c.ItemNo,c.Description,c.Qty from ItemParent a,CustomerDetail b,ItemParent c INNER JOIN  b ON a.CusId = b.CusId,INNER JOIN  c ON c.DoNumber = b.DoNumber";
            SqlCommand cmd = new SqlCommand(selectcmd, conn);
            conn.Open();
            reader = cmd.ExecuteReader();
            conn.Close();


Thanks
Posted

SELECT a.DoDate,a.DoNumber,a.CusId,b.CompName,b.CompAddress,b.Tel,b.Fax,b.ContPerson,b.SalesPerson,c.ItemNo,c.Description,c.Qty from ItemParent a inner join CustomerDetail b ON a.CusId = b.CusId inner join ItemParent c ON c.DoNumber = b.DoNumber"

Use this above query and let me know.....
 
Share this answer
 
Use this query instead:
SQL
SELECT a.DoDate,
a.DoNumber,
a.CusId,
b.CompName,
b.CompAddress,
b.Tel,b.Fax,
b.ContPerson,
b.SalesPerson,
c.ItemNo,
c.Description,
c.Qty
from ItemParent 
INNER JOIN CustomerDetail b ON a.CusId = b.CusId
INNER JOIN ItemParent c ON b.DoNumber = c.DoNumber

Regards,
Eduard
 
Share this answer
 
v2
try this:
C#
private void BindGridData()
{
  DataTable dt = new DataTable();
  strSql = "SELECT EmpView.EMP_NAME,EmpView.DESIG_NAME, EMP_PUBLICATION.EMPCODE,EMP_PUBLICATION.TITLE, EMP_PUBLICATION.DOWNLOADFILE ,EMP_PUBLICATION.EXT_LINK, EMP_PUBLICATION.ENTRY_DATE "
              + " FROM  EMP_PUBLICATION INNER JOIN "
                      + "EmpView ON EMP_PUBLICATION.EMPCODE = EmpView.EMP_ID ";
  dt = ObjGenFun.execute_dataset("TR", strSql).Tables[0];
  GridShow.DataSource = dt;
  GridShow.DataBind();
}
 
Share this answer
 
v3
 
Share this answer
 
just use query builder in server explorer..then clik the table wat u needed..then u can select the required fields...so that inner join will be done between tables...very simple..no need of keys also for these methods in table
 
Share this answer
 
Comments
Lancy.net 24-Nov-11 22:52pm    
Thanks Vinoth

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