简体   繁体   中英

inner join using Linq Vb.net

I'm trying to join two datatables of same keyfields.

table1

ID     Class    
----   -----
1       10  
2       9   

table2

ID     Class
----   -----
1       8   
2       7   

Result

ID      Class1    Class2
1        10       8
2        9        7

following is code for joining between user and userclients you can replace your table and get the result of join

Follwing image is for the c# but will give you idea in detail

在此处输入图片说明

Dim user = From u In Users Join uc In UserClients On u.Id = uc.UserId New From { _
    u.Id, _
    u.FirstName, _
    u.LastName, _
    uc.MobileNo, _
    uc.imeiNO, _
    uc.Id _
}

if you are beginner you can look this : SQL to LINQ ( Visual Representation )

try something like this:

Dim test = From t1 in table1_
       Join t2 in table2 on t1.ID Equals t2.ID _
       Select  ID = t1.ID,
               Class1 = t1.Class,
               Class2 = t2.Class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM