skaleem1
asked on
Single quote in a text field data in SQL Sever causes to throw an error when displayed in Gridview
I have the following SQL Query:
SELECT CurrencyID, Currency, [ISO-4217], Symbol FROM Currencies
The Currency column has one row value as:
Tongan Pa'anga
When I try to bind data to a gridview in the code behind (see the code section), I see the error (Please see the screen shot image file) that points to the following line of html generated code:
</tr><tr>
<td style="border-color:#344F3 E">Tongan Pa'anga</td><td style="border-color:#344F3 E">TOP</td ><td style="border-color:#344F3 E">T$</td> <td style="border-color:#344F3 E">Tonga</ td><td style="color:#344F3E;borde r-color:#3 44F3E"><a href="javascript:__doPostB ack('ctl00 $ContentPl aceHolder1 $GridView1 ','Edit$22 0')" style="color:#344F3E;">Edi t</a></td> <td style="color:#344F3E;borde r-color:#3 44F3E"><a onclick="return ConfirmOnDelete('Tongan Pa'anga');" class="LinkButton" href="javascript:__doPostB ack('ctl00 $ContentPl aceHolder1 $GridView1 ','Delete$ 220')" style="color:#344F3E;">Del ete</a></t d>
</tr>
The issue is with the single quote and if I remove the single quote from the text, the error is removed. How can I resolve this issue? Should I change my query (see above) and replace the single quote with CHR(34) in the SQL? Please help.
SELECT CurrencyID, Currency, [ISO-4217], Symbol FROM Currencies
The Currency column has one row value as:
Tongan Pa'anga
When I try to bind data to a gridview in the code behind (see the code section), I see the error (Please see the screen shot image file) that points to the following line of html generated code:
</tr><tr>
<td style="border-color:#344F3
</tr>
The issue is with the single quote and if I remove the single quote from the text, the error is removed. How can I resolve this issue? Should I change my query (see above) and replace the single quote with CHR(34) in the SQL? Please help.
this.GridView1.DataKeyNames = new string[] { "CurrencyID" };
this.GridView1.Columns.Add(new BoundField() { DataField = "CurrencyID", HeaderText = "CurrencyID", Visible = false });
this.GridView1.Columns.Add(new BoundField() { DataField = "Currency", HeaderText = "Currency",SortExpression="Currency" });
this.GridView1.Columns.Add(new BoundField() { DataField = "ISO-4217", HeaderText = "[ISO-4217]",SortExpression="ISO-4217" });
this.GridView1.Columns.Add(new BoundField() { DataField = "Symbol", HeaderText = "Symbol",SortExpression="Symbol" });
DataTable dt = LU.Tables[CURRENCIES];
GridView1.DataSource = dt;
GridView1.DataBind();
SingleQuoteError.JPG
onclick="return ConfirmOnDelete('Tongan Pa\'anga')
or
onclick="return ConfirmOnDelete('Tongan Pa''anga')
or
onclick="return ConfirmOnDelete('Tongan Pa''anga')
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Tongan Pa''anga