Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<pre lang="text">I have two table and how to create the relationship in c# 
1)TBL_PDT(product),pdt_id (primary key),pdt_name,pdt_description;
2)TBL_SIMILAR_PDT(similar product),sid(foreign key of TBL_PDT),sim L_PDT),sim_pdt_id(foreign key of TBL_PDT),sim_pdt_desc;

1)how to call the same product id from same foreign key table (TBL_SIMILAR_PDT)?

2)how to values are dropdownlist1(pdt_id) and dropdownlist2(pdt_id)?



PLEASE HELP ME!!!
Posted
Updated 12-Feb-14 19:41pm
v3

1 solution

Use a bit of SQL similar to this to return similar items:

SQL
select * from tbl_similar_pdt where ((sid = VALUE) or (sim_pdt_id = VALUE))
 
Share this answer
 
Comments
jeevakumar.T 13-Feb-14 2:08am    
I have another question Sir?

1)TBL_PDT(product)fields(pdt_id(prmary key),pdt_name,pdt_desc);
2)TBL_SIMILAR_PDT(similer product)fields(sim_id,pdt_id(foreign key<TBL_PDT>),sim_pdt_id(foreign key<TBL_PDT>),sim_desc);

how to call foreign key values pdt_id and sim_pdt_id for a same primary key table
_Damian S_ 13-Feb-14 19:22pm    
select Prod.pdt_name as ProductName, SimProdLeft.pdt_name as SimProdNameLeft, SimProdRight.pdt_name as SimProdNameRight
from tbl_pdt Prod
left join tbl_similar_pdt SimProdLeftJoin on Prod.pdt_id = SimProdLeftJoin.pdt_id
left join tbl_pdt SimProdLeft on SimProdLeftJoin.pdt_id = SimProdLeft.pdt_id
left join tbl_similar_pdt SimProdRightJoin on Prod.pdt_id = SimProdRightJoin.sim_pdt_id
left join tbl_pdt SimProdRight on SimProdRightJoin.sim_pdt_id = SimProdRight.pdt_id

It's all about aliasing your tables - that way you can call the same table multiple times.

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