LINQ oddity...
-
Hi All, I'm new to Linq. I've got the following code to take two tables, and result in the rows from table1 that are NOT in table2. The Linq is out of the book <u>Pro Linq</u> from Apress. Dim seq1 As IEnumerable(Of DataRow) = table1.AsEnumerable() Dim seq2 As IEnumerable(Of DataRow) = table2.AsEnumerable() Dim except As IEnumerable(Of DataRow) = seq1.Except(seq2, System.Data.DataRowComparer.Default) Dim Table3 As New DataTable Dim NewTableColumn As DataColumn = Table3.Columns.Add("UserName") 'For Each row resulting from LINQ query, add to new table. For Each dr As DataRow In except Dim NewRow1 As DataRow = Table3.NewRow() NewRow1("UserName") = dr.Item(0).ToString Table3.Rows.Add(NewRow1) Next Obviously I don't understand something about Linq. When the page runs through the procedure for the first time, everything works. The variable "except" contains the correct rows. However, after binding and postback, though I've confirmed that Table1 and Table2 contain the correct rows, the linq doesn't respond as expected. It's as if it is doing nothing at all. Any thoughts on this? Thanks in advance!
-
Hi All, I'm new to Linq. I've got the following code to take two tables, and result in the rows from table1 that are NOT in table2. The Linq is out of the book <u>Pro Linq</u> from Apress. Dim seq1 As IEnumerable(Of DataRow) = table1.AsEnumerable() Dim seq2 As IEnumerable(Of DataRow) = table2.AsEnumerable() Dim except As IEnumerable(Of DataRow) = seq1.Except(seq2, System.Data.DataRowComparer.Default) Dim Table3 As New DataTable Dim NewTableColumn As DataColumn = Table3.Columns.Add("UserName") 'For Each row resulting from LINQ query, add to new table. For Each dr As DataRow In except Dim NewRow1 As DataRow = Table3.NewRow() NewRow1("UserName") = dr.Item(0).ToString Table3.Rows.Add(NewRow1) Next Obviously I don't understand something about Linq. When the page runs through the procedure for the first time, everything works. The variable "except" contains the correct rows. However, after binding and postback, though I've confirmed that Table1 and Table2 contain the correct rows, the linq doesn't respond as expected. It's as if it is doing nothing at all. Any thoughts on this? Thanks in advance!
Member 4125480 wrote:
It's as if it is doing nothing at all.
This is weird.. There must be some problem with Datatables. Otherwise how it is possible.. :wtf:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml> -
Member 4125480 wrote:
It's as if it is doing nothing at all.
This is weird.. There must be some problem with Datatables. Otherwise how it is possible.. :wtf:
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Microsoft Bing MAP using Javascript
CLR objects in SQL Server 2005
Uncommon C# Keywords/xml>You were right. I had made a booboo previously in my datatables. It works now. :)