VB.Net Query Error

Posted on 2012-08-20
Medium Priority
Last Modified: 2012-08-20

I've been creating queries for my program and I ran into an odd error in VB.Net.  What happens is, when I run the program and use the query, the program closes and gives me the following error.  Cannot perform 'Like' operation on System.DateTime and System.String.  What I want for this query to do is allow the user to search dates.  

Lets say I had a record that has the date 5/16/2011.  I want to be able to type 5 into the query and see all the records that contain 5/--/----  and so on.  I believe this is done by using a textchanged property but alas I have that error.

Here is the code I have been using:
Private Sub txtOrder_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtOrder.TextChanged
        If txtOrder.TextLength > 0 Then
            All_flood_certsBindingSource.Filter = String.Format("[Order Received] Like '" & txtOrder.Text) & "'"
            All_flood_certsBindingSource.Filter = String.Empty
        End If
    End Sub

Open in new window

If anyone can shed some light on this issue I would be greatly thankful!
Question by:hydrazi
1 Comment
LVL 13

Accepted Solution

LIONKING earned 2000 total points
ID: 38312257
Since the datatype is a date, I don't think you can use the LIKE operator.
If you're working on MSSQL you'd have to use DATEPART and (probably) EXTRACT on MySQL.

Of course, you'd also have to validate what part of the date the user is entering (Month, Day or Year) and change the "unit" in function accordingly.

Hope it helps.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

749 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