Am very bad in Linq query so need your help. I am matching 2 coloumns data from diff data table and joining both the datatables basis match. Please suggest me linq qeury. I tried JOIN Data tables, but it didnt work as its showing 0 match but when am checking manually, there is match.
Can you please provide more details about the structure of your data tables and the specific columns you want to match? Also, let us know if you have any specific conditions or criteria for the matching process.
(From a In Dt1.AsEnumerable()
Join b In Dt2.AsEnumerable()
On a("matching_Column") Equals b("Matching_Column")
Select OutputDataTable.Rows.Add({a("Matching_Column"), a("Col_1"), a("Col_2"), b("Col_3"), b("Col_4")})
).CopyToDataTable()
Dim joinedData = From row1 In dt1.AsEnumerable()
Join row2 In dt2.AsEnumerable()
On row1.Field(Of String)("J") Equals row2.Field(Of String)("K")
Select New With
{
.Column1 = row1.Field(Of String)("J"),
.Column2 = row2.Field(Of String)("K")
}
Dim dtResult As New DataTable()
dtResult.Columns.Add("Column1")
dtResult.Columns.Add("Column2")
For Each item In joinedData
Dim newRow As DataRow = dtResult.NewRow()
newRow("Column1") = item.Column1
newRow("Column2") = item.Column2
dtResult.Rows.Add(newRow)
Next
var query = from row1 in dt1.AsEnumerable()
join row2 in dt2.AsEnumerable()
on row1.Field(“Column1”) equals row2.Field(“Column2”)
select new
{
Column1 = row1.Field(“Column1”),
Column2 = row2.Field(“Column2”),
// Add other columns you want to include in the result
};