Searching a Database using Binding source for week numbers in Visual Basic

Gary Simpson 471 Reputation points
2021-06-12T10:06:08.967+00:00

Hi Good People,

I am trying to write code for searching my Database for week numbers, But I keep getting an error. ( System Data Evaluate Exception). (Filter expression '0' does not evaluate to a Boolean term, )
Does any of you good people know how to search for numeric values using a binding source.

The code I am getting an error with is.

Function GetDouble(s As String) As Double
        Dim v As Double = 0.0
        If Double.TryParse(s, v) Then Return v
        Return 0.0
    End Function

    Private Sub TxtFilterWeek_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TxtFilterWeek.KeyPress
        'Search for week Number
        Dim FilterWeek As Double = GetDouble(TxtFilterWeek.Text)
        If String.IsNullOrWhiteSpace(TxtFilterWeek.Text) Then
            PaidInvoicesBindingSource.Filter = ""
        Else

            PaidInvoicesBindingSource.Filter = GetDouble($"WeekNumber LIKE '%{TxtFilterWeek.Text}%'")
        End If
    End Sub

in the database I created the week number is Numeric, (18,0)

Can you point me in the right direction Please

Kindest Regards
Gary

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,822 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 121.3K Reputation points
    2021-06-12T10:12:32.82+00:00

    Try removing GetDouble:

    PaidInvoicesBindingSource.Filter = $"WeekNumber LIKE '%{TxtFilterWeek.Text}%'"
    

    or maybe

    PaidInvoicesBindingSource.Filter = $"WeekNumber = {FilterWeek}"
    

    Also exclude the erroneous (non-number) values of TxtFilterWeek.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.