in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Simple filter query produces no results

Last post 12-05-2011 5:31 PM by quickdraw. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-25-2009 2:49 AM

    • Chew
    • Top 75 Contributor
    • Joined on 06-23-2009
    • Posts 18

    Simple filter query produces no results

    Hi there, I hope someone can help because this makes no sense to me!

    I am working in C# (VS2005 sp1), with SQLite build 62.

    I create a table adapter based on the following SQL:

    SELECT    
        products.products_barcode,
        products.products_name,
        products.products_salePrice * (1 + @stdMarkup / 100) AS salePrice,
        manufacturers.manufacturer_name,
        categories.category_name,
        categories.category_id,
        manufacturers.manufacturer_id,
        products.products_id
    FROM
        products
        INNER JOIN    manufacturers ON products.products_manufacturer_id = manufacturers.manufacturer_id
        INNER JOIN    categories ON products.products_category_id = categories.category_id
    WHERE   
        (products.products_name LIKE '%' + @prod_filter + '%')
    OR
                (manufacturers.manufacturer_name LIKE '%' + @man_filter + '%')
    OR
                (categories.category_name LIKE '%' + @cat_filter + '%')
    OR
        (products.products_barcode = @bar_filter)

    The method that calls this SQL is called GetFilteredData (see below).

    In code, I use the following to retrieve filtered product data:

    localDataSetTableAdapters.productFilterTableAdapter productsAdapter = new localDataSetTableAdapters.productFilterTableAdapter();
    productsAdapter.Connection.ConnectionString = "Data Source = " + generic.programFolder() + "data.s3db" + "; Version=3";

    string filter = tbSearchString.Text;
    localDataSet.productFilterDataTable productsTable = productsAdapter.GetFilteredData(this.stdMarkUp, filter, filter, filter, filter);

     

    The productsTable never gets populated with data. Always 0 rows. I have checked and the data is there, the query runs fine against the SQL server with the same data.

    Am I missing something?

    Thanks, in anticpation of a solution.

    Chew

  • 06-25-2009 5:12 AM In reply to

    • Knch
    • Top 50 Contributor
    • Joined on 02-10-2009
    • Posts 30

    Re: Simple filter query produces no results

    In SQLite string are concatenated with || not +, so '%' || @prod_filter || '%' should do the trick...
  • 06-25-2009 7:04 AM In reply to

    • Chew
    • Top 75 Contributor
    • Joined on 06-23-2009
    • Posts 18

    Re: Simple filter query produces no results

     Hi Knch

     Thanks for your reply.

    I tried using || in the SQL for my table adapter but Visual Studio says it's illegal syntax. Are we saying that SQLite is incompatible in this way with VS?

    Chew

  • 06-25-2009 9:12 AM In reply to

    Re: Simple filter query produces no results

    VS doesn't recognize the syntax, but SQLite does.  Just hit OK to continue and VS will send the statement onto SQLite as-is.

  • 12-05-2011 5:31 PM In reply to

    Re: Simple filter query produces no results

     In VS 2010, this non-standard (SQL) concat operater wreaks all sorts of havoc with the data source designers.You can't edit data sources with either the designer or the data source wizard. In the sqlite db, you have to create a SQL view that does the concat for you and bind to that.

Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems