Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two tables

In table1 i have following fields:
HTML
id
Name


In table2 i have following fields
HTML
tid
id
skill
proficiency


the table1 filled with data looks like
HTML
id   Name
R1  abc
R2  xyz

the table2 filled with data looks like
HTML
tid   id   skill         proficiency
1     R1   .net         high
2     R1    sql          low
3     R1    jquery    low
4     R2    .net        low

now i want to create a datatable that will contain all information regarding id R1 i.e Name, all skills along with their proficiency....
Posted
Updated 31-Aug-12 3:14am
v3
Comments
ssd_coolguy 31-Aug-12 7:59am    
can you elaborate more?
sp1786 31-Aug-12 8:02am    
i want this datatable to populate a report(.rdlc) .. text box will be populated with 'NAme' and the matrix structure will show the list of skills and profficiencies...
Suraj S Koneri 31-Aug-12 8:01am    
you can merge these tables on based on id and get result.
sp1786 31-Aug-12 8:04am    
how to merge?? coz for table 2 no. of rows are returned but for table1 just 1 row is returned...
ssd_coolguy 31-Aug-12 8:10am    
if i m correctly understands your problem then you need data like..

abc R1 .net high
abc R1 sql low
abc R1 jquery low
xyz R2 .net low

you can do it using join to...

SQL
SELECT t1.Name, t2.Skill, t2.Proficiency
FROM table1 t1 
INNER JOIN table2 t2 ON t1.ID = t2.ID
WHERE t1.ID = 'R1'


This will give you the name, skill, and proficiency where the ID is R1.
 
Share this answer
 
Comments
ridoy 31-Aug-12 8:20am    
correct..+5
D-Kishore 3-Sep-12 1:32am    
yes its fine 5 :)
SQL
SELECT tbl1.Name, tbl2 .Skill, tbl2 .Proficiency
FROM table1 tbl1
INNER JOIN table2 tbl2 ON t1.ID = t2.ID
WHERE tbl1.ID = r1
 
Share this answer
 
v2
Comments
Anuja Pawar Indore 31-Aug-12 9:15am    
Added code block
C#
var allRows =
    from
        dataTable1Rows in dataTable1.AsEnumerable()
    join
        dataTable2Rows in dataTable2.AsEnumerable()
    on
        dataTable1Rows.Field<int>("ID") equals dataTable2Rows.Field<int>("ID")
    select
        dataTable2Rows;

DataTable joinedDataTable = allRows.CopyToDataTable();

and this joinedDataTable you can bind to rdlc , if you want to do it at c# side , otherwise if you want a sql server query a simple join between two tables should work
SQL
SELECT table1.ID ,table1.Name, table2.Skill, table2.Proficiency
FROM datatable1 table1
INNER JOIN datatable2 table2 ON table1.ID = table2.ID where table1.ID='R1'

Hope this helps

Regards,
Harika Kakkireni
 
Share this answer
 
v8

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