Filtering Gridview

Discussion in 'ASP .Net' started by Mark B, Jan 27, 2009.

  1. Mark B

    Mark B Guest

    This code works fine to filter a Gridview:

    With SqlDataSource3
    .FilterExpression = "LanguageText LIKE '%{0}%'"
    .FilterParameters.Clear()
    .FilterParameters.Add("fp2", TextBox4.Text)
    End With



    unless the text entered in TextBox4.Text includes a single quote '

    Then an error is given:

    - 'always
    Syntax error: Missing operand after 'always' operator.

    - alway's
    Syntax error: Missing operand after 's' operator.

    - always'
    The expression contains an invalid string constant: '.


    Suggestions?
     
    Mark B, Jan 27, 2009
    #1
    1. Advertisements

  2. string textBoxValue = TextBox1.Text.Replace("'", "''");
     
    Cowboy \(Gregory A. Beamer\), Jan 27, 2009
    #2
    1. Advertisements

  3. Mark B

    Mark B Guest

    Thanks that worked:

    With SqlDataSource3
    .FilterExpression = "LanguageText LIKE '%{0}%'"
    .FilterParameters.Clear()
    .FilterParameters.Add("fp2", TextBox4.Text.Replace("'",
    "''"))
    End With
     
    Mark B, Jan 27, 2009
    #3
  4. The single quote is the bane of database programmer's existence. ;-)
     
    Cowboy \(Gregory A. Beamer\), Jan 27, 2009
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.