Escaping single quote with bound control - how??

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I have some controls on a form bound to a dataset.

When it comes to update time, I manually set up parameters using the
following syntax

command.Parameters.Add("@documenttitle", SqlDbType.VarChar, 200,
"documenttitle")

where the last parameter is the field in the dataset to use. However
if in my textbox control I type something with a single quote in it
such as "O'Neill" how do I escape this to two single quotes before it
goes to the update?

It surely can't be the case that bound controls are no good unless you
prevent users from typing single quotes?
 
Mark,

You can use the parse and format events of the databinding object to convert
a single quote in a text box into an escape character in the data source
(parse) and then convert back to a single quote when you move data from the
data source back to the control (format).

Matt
 
Mark,

Another approach would be to create the parameter object first and then set
the "value" property to your string value. The parameter object will take
care of escaping the single quote for you.

Eric
 
Back
Top