Here is my code
Dim dr2 As PBRuleData.PBRuleRow
Dim query As IEnumerable(Of PBRuleData.PBRuleRow) = From s In Me.PBRule.PBRule.AsEnumerable() _
Where s.PBRuleId = .PBRuleId And s.StartDate <= .PBDate _
And (s.IsFinishDateNull Or (s.FinishDate > .PBDate)) Select s
If query.Count > 0 Then
dr2 = query.ElementAt(0)
If Not (dr2.IsHoursNull) Then
If dr2.IsBilling Then
dblHoursBILL += CType(dr2.Hours, Double)
Else
dblHoursPAY += CType(dr2.Hours, Double)
End If
End If
End If
Even though I have put s.IsFinishDateNull condition to avoid null exception but its still causing exception The value for column 'FinishDate' in table 'PBRule' is DBNull.
this linq query is an alternate to this datatable query which works fine.
Dim dr As DataRow()
Dim sQuery As String
sQuery = "PBRuleId={0} AND StartDate<=#{1:MM/dd/yy}# AND (FinishDate>=#{1:MM/dd/yy}# OR FinishDate IS NULL)"
dr = Me.PBRule.PBRule.Select(String.Format(sQuery, .PBRuleId, .PBDate))
If dr.Length > 0 Then
If Not (dr(0).Item("Hours") Is DBNull.Value) Then
If dr(0).Item("IsBilling").ToString().ToLower = "true" Then
dblHoursBILL += CType(dr(0).Item("Hours").ToString(), Double)
Else
dblHoursPAY += CType(dr(0).Item("Hours").ToString(), Double)
End If
End If
End If
Can anyone help