[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 884
  • Last Modified:

Inner Join with Dataset

asp.net
Can anyone help me to make a "INNER JOIN" with two dataset? To bind them in a grid

I have this

1) DataSet dtInventario
NAME                   IP
==============     ===========
EXCHANGE01        192.168.100.1
DC01              192.168.100.5
DC02              192.168.100.29
SR01              192.168.100.15
FL01              192.168.100.22

Open in new window


2) DataSet dtExcel
NAME                   
==============    
EXT99
EXT22
EXCHANGE01
null
FL01
BART00

Open in new window


3) Result NEWDATASET
NAME                   IP
==============    ===========
EXCHANGE01        192.168.100.1
FL01              192.168.100.22

Open in new window


If "NAME" from  dtExcel exist in  dtInventario then return "NAME" and "IP" from  dtInventario

maybe with linq?

Thank you so much!!!
0
Sherman Guti
Asked:
Sherman Guti
  • 2
  • 2
1 Solution
 
käµfm³d 👽Commented:
Try something like this:
var results = from item1 in dtInventario.Tables[0].AsEnumerable()
              join item2 in dtExcel.Tables[0].AsEnumerable()
              on item1.Field<string>("Name") equals item2.Field<string>("Name")
              select new
              {
                  Name = item1.Field<string>("Name"),
                  IP = item1.Field<string>("IP")
              };

Open in new window

0
 
Sherman GutiAuthor Commented:
thanks!!! i'll try in my work tomorrow...!!! here in argentina is night
0
 
Sherman GutiAuthor Commented:
Thank you kaufmed. I'm using VB... when I try to convert from c# to vb I have problems in this part

select new
              {
                  Name = item1.Field<string>("Name"),
                  IP = item1.Field<string>("IP")
              };

Open in new window



Can you give me a little help to covnert this?
0
 
käµfm³d 👽Commented:
It should be:
Select New With {
                    .Name = item1.Field(Of String)("Name"),
                    .IP = item1.Field(Of String)("IP")
                }

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now