Selecting from a column with Ampersand(&)

757 views Asked by At

The data type of the column is nvarchar. I can insert to the column properly using parameters. I see the ampersand character in the column when I view the table in sql server management studio.

My problem is when i'm selecting from the column in my application the ampersand character disappears.

Once I select the column I assign the value to a label like, label1.Text = reader("column")

The column in my table has a value of "Foo&Bar" but in my application it just shows as "FooBar".

2

There are 2 answers

0
Eric On

It is a property of the Label called UseMnemonic, set it to False to show the text & properly

0
crimson On

Looks like the ampersand was turning the next letter to a shortcut.

I just did a replace on the ampersand to 2 ampersands so it escapes.

label1.Text = reader("column").ToString().Replace("&", "&&")