Getting Error in BindingSource Filter?

Posted on 2013-09-02
Medium Priority
Last Modified: 2013-09-08
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
Question by:BlakeMcKenna
  • 2
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 39459583
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

Accepted Solution

BlakeMcKenna earned 0 total points
ID: 39460537
I already read that MSDN topic. Plus, I did go ahead and add a Year AND a Month column since the query needed both values.

Author Closing Comment

ID: 39474102
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.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
If you are looking for an automated tool which can generate reports for Outlook emails and other items from PST file, then you can go for Kernel PST Reporter tool. The reports which are created by this tool are helpful to analyze and understand PST …
Watch the video to know the simple way to remove or recover or reset lost or forgotten passwords of Outlook PST file. With Kernel Outlook Password Recovery tool such operation is very easy to perform. It is a freeware with limitation to use with 500…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question