Hi,
I am trying use LINQ t join two different tables. I have to loop through an array list to obtain the two data tables.
Currently I am using a for loop to go through the array list and then obtain the result for each data table. I have only one row in each data table for one value in array list.
I am using LINQ to join these two datatables. I am sending this LINQ join to a data set and then to a gridview to display results. I am unable to do anything like dataset.add so that it can store all the LINQ results and display all of them in gridview. In other words, I am unable to display all the resultant rows of LINQ in a data grid. here is my code,
dr2,dr3 are IDataReader and has one row each. these rows are the result of an sql which has class_number as input. so as i iterates, I pass each class_number to get the results for each dr2, dr3. hope I am clear.
please let me know how to proceed on this. thank you for your time.
I am trying use LINQ t join two different tables. I have to loop through an array list to obtain the two data tables.
Currently I am using a for loop to go through the array list and then obtain the result for each data table. I have only one row in each data table for one value in array list.
I am using LINQ to join these two datatables. I am sending this LINQ join to a data set and then to a gridview to display results. I am unable to do anything like dataset.add so that it can store all the LINQ results and display all of them in gridview. In other words, I am unable to display all the resultant rows of LINQ in a data grid. here is my code,
dr2,dr3 are IDataReader and has one row each. these rows are the result of an sql which has class_number as input. so as i iterates, I pass each class_number to get the results for each dr2, dr3. hope I am clear.
Code:
For i As Integer = 0 To CLASS_NUMBER.Length - 1
Dim dt2 As New DataTable
dt2.Load(dr2)
Dim dt3 As New DataTable
dt3.Load(dr3)
Dim ds As New DataSet
Dim joinquery = From t1 In dt2.AsEnumerable() Join t2 In dt3.AsEnumerable() _
On t1.Field(Of Decimal)("CLASS_NUMBER") Equals t2.Field(Of Decimal)("CLASS_NUMBER") _
Select New With _
{Key .CLASS_NUMBER = t1.Field(Of Decimal)("CLASS_NUMBER"), _
Key .FACULTY_START_DT = t2.Field(Of DateTime)("FACULTY_START_DT"), _
Key .FACULTY_END_DT = t2.Field(Of DateTime)("FACULTY_END_DT"), _
}
ds = joinquery
' here I want something to keep adding my results to data set so that I can dispaly all the rows in the gridview.
next
'NewDg is a gridview.
NewDg.DataSource = ds
NewDg.DataBind()