question

GarySimpson-0619 avatar image
0 Votes"
GarySimpson-0619 asked GarySimpson-0619 commented

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

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



dotnet-visual-basic
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered GarySimpson-0619 commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Viorel-1

Thank you for getting back to me, I started with the code you suggested, But I was still getting the error.

Is what I might try is changing the Database from numeric to Varchar (2), But this will mean I will have to change all the tables in my Database with week number in the table.

Thank you Viorel

0 Votes 0 ·