filtering in the webGrid - wildcard on Int? RRS feed

  • Question

  • User379720387 posted

    My table has a column BillNo with datatype int

    It has integers or NULL's as values.

    In my select I have SELECT BillNo WHERE ProviderId=@0 AND BillNo LIKE @1

    The wildcard  for parameter @1 equals:

    var billno = "%" + Request ["billno"] + "%";

    I am at a loss why this is not working. There is a single record with BillNo = NULL

    Friday, December 12, 2014 3:01 PM


  • User-821857111 posted

    You can't use LIKE with numbers. I'm assuming that you are working with SQL CE? The simplest solution is to build the query conditionally:

    var sql = "SELECT BillNo WHERE ProviderId=@0 ";
        sql += " AND BillNo = @1";
    var billNo = db.QueryValue(sql, provider, Request["billno"]);

    The last parameter will be ignored if there is no placeholder for it.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, December 12, 2014 3:25 PM