Filtering Gridview

M

Mark B

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?
 
C

Cowboy \(Gregory A. Beamer\)

string textBoxValue = TextBox1.Text.Replace("'", "''");

--
Gregory A. Beamer
MVP; MCP: +I, Se, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

*************************************************
| Think outside the box! |
*************************************************
 
M

Mark B

Thanks that worked:

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

Cowboy \(Gregory A. Beamer\)

The single quote is the bane of database programmer's existence. ;-)

--
Gregory A. Beamer
MVP; MCP: +I, Se, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

*************************************************
| Think outside the box! |
*************************************************
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top