VB.NET: LINQ Query on DataTable - WHERE Id >=0
09:26 20 May 2016

Hey people,

I am bugfixing an application for some friends of mine. They are using VB.NET and Windows Forms, while I am in team C#/WPF/ASP. My knowledge about LINQ is also very limited even if its all .NET. I hope you can help me.

The situation
There are two combos on the form. They are getting their data from the same table status.
The order of the status objects depends on the id-column.
The second combo shall only contain status having id >= combo1.id. So that the user can only select status in the second combo that are "greater-equal" than the status in the first combo.
The smallest status.id is 3.

The code
(please ignore the useless back and forward casting of index etc. I wanted to show you the code as I revieved it.)

                    Dim index As String = cmbStatusFrom.SelectedValue.ToString()
                    If index = "0" Then
                        index = "1"
                    End If

                    Dim query As IEnumerable(Of DataRow) = _
                        From status In ContextDataTable.AsEnumerable() _
                        Where status.Field(Of Integer)("Id") >= Integer.Parse(index) _
                        Select status

The problem
Without

If index = "0" Then  
    index = "1"  
End If

the resulting datatable contains one more row than it should. (0 means that the empty-item has been selected in the first combo) The row has id = 0 (like the empty-row)

Again, the smallest existing id is 3. So it should not make any difference if one uses >=0, 1, 2 or 3. But it seemingly does. Or more likely, there is some really stupid mistake in the code and which I just can't find.

Anyone has got an idea what the problem is?

I do appreciate any help. :-)

greetz steven

database vb.net linq