VB.Net Query Error

Posted on 2012-08-20
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

    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

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now