Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

Getting Error in BindingSource Filter?

I'm getting an error when I set my BindingSource Filter property to the following string.

                        strFilter = " YEAR(dateOfTran) = " & CInt(Trim(cmbYear.Text)) & " AND MONTH(dateOfTran) = " & GetMonthLiteral(0, cmbMonth.Text)

I get the Error Message:  "The expression contains undefined function call YEAR()". I created a SQL Query that used this string and ran it in SQL Server Management Studio and it ran fine. What am I missing. Here is the actual code below.

                        strFilter = " YEAR(dateOfTran) = " & CInt(Trim(cmbYear.Text)) & " AND MONTH(dateOfTran) = " & GetMonthLiteral(0, cmbMonth.Text)
                    bsTransactions.Filter = strFilter

Here is what the strFilter looks like after I run it through the Debugger:

    YEAR(dateOfTran) = 2013 AND MONTH(dateOfTran) = 8
Avatar of Gautham Janardhan
Gautham Janardhan

you need to stick to this http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx

you may want to add a new column year whicch will be year of dateOfTran and then filter based on that
ASKER CERTIFIED SOLUTION
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BlakeMcKenna

ASKER

After I looked at the MSDN Topic as well as other posts from various sites, I realized that would probably be my best solution for what I needed.