.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Strange problem, unable to insert single quote (already add in an extra single quote) for one partic

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :Sql Server
I have a very strange problem, I can update the table with single quote, but I cannot insert single quote. It only happen for this particular table in the database. Is there any suggestion on what I should look at?

I had already added in an extra single quote in my sql statement, something like this:

insert into Table_1 VALUES ('hello's world','xxx')

View Complete Post

More Related Resource Links

Javascripts single quote problem


Hi ,

I am calling a popup from anchor inside a gridview.

<a href="javascript:ShowSiteVirtualProfile('<%#Eval("Site").ToString().Replace("'", "\'")%>','<%#DataBinder.Eval(Container.DataItem,"Query").ToString().Replace("'", "\'")%>')"><%#DataBinder.Eval(Container.DataItem,"Site")%></a>

Its works fine. But a single quote in the text popup is not working.

Please give me a solution what I need to do now.

XML Column containing single quote causes replication error

We have SQL Server 2005 transactional replication set up, and some of our tables have XML datatype columns.  We have run into an issue with the following error in the publication: Incorrect syntax near 's'. (Source: MSSQLServer, Error number: 102) Get help: http://help/102 Looking at the distribution database, I was able to extract the offending command, and it turns out that the XML column has a single quote (') embedded in it, and the command that was generated for inserting the row into the subscriber table has bad syntax because of the single quote (i.e., it is not escaped).  One interesting note is that the single quote happens to also show up in a non-XML column, and the command segment for that column was generated correctly (it was escaped). Is there a workaround / solution for this?

Problems with single quote character when attempting to export data from SQL Server

Hi, I am attempting to use the following query, which works fine when run in sql server management studio, to export data: SELECT             '1',             isnull(left(DISTRICT,1),' '),             isnull(left(CTV,2),'  '),             isnull(left(CTV2,5),'     ')           FROM [CensusData].[dbo].[MainQuestionnaire$] The export command follows: EXEC xp_cmdshell 'bcp "SELECT             '1',             isnull(left(DISTRICT,1),' '),             isnull(left(CTV,2),'  '),             isnull(left(CTV2,5),'     ')             FROM [CensusData].[dbo].[MainQuestionnaire$]" queryout "C:\bcptest.txt" -T -c -t -S "MYSERVER"' The error is: Incorrect syntax near '1'. I believe that the problem is with the single quote characters but don't know how to fix it. I am using SQL Server 2005 Express edition. Please help.

How to replace ' to single quote in XSLT


I have a DataView webpart in my Sharepoint  page.And I converted it to XSLT view for conditional formatting.My requirement is i need to get the Text of a column (of DataView )in a correct format with the property  disable-output-escaping="no" condition.Here Iam explaining the scenario my actual text is

 This is text of dvcolumn at share's Desk .But I am getting it as
 This is text of dvcolumn at share&#39;s &amp; Desk. I need to replace apostrope(or single quote ()')  at  &#39; and  space at &amp; .I used truncate function at DataView's EditFormula option .But I dint get it properly can any one help me out in this??

How to exclude single quote?




I have a string like 12 ju 'kold dsd' 15g.

And I wanna get 4 separated strings: 12, ju, kold dsd & 15g.

I have implemented next pattern: ([0-9a-zA-Z:=\|]+)|'[ 0-9a-zA-Z:=\|]+'

It has given next result: 12, ju, 'kold dsd' & 15g.

How to exclude quotes by means of RegExp?

Preventing cross-site scripting and encoding a single quote


I'm trying to prevent possible cross-site scripting attacks for our internal use app (but available publicly outside the firewall).

One feature of our app is a javascript based breadcrumb that keeps track of prior urls (via nice titles). Everytime, a new page is loaded in the current workflow, when that page renders as the browser, it includes some javascript (generated server side in C# and put into the page) to add itself to the breadcrumb trail. Currently, the url that is launched is given directly to that javascript function. However, if that url contains a single quote it is possible to inject some custom javascript, ie, one would just need to append    ');alert('yeah!');       to their url.

I tried encoding/escaping but they skip the single quote. This is a case where I'm just passing the url through. But theoretically, if an attacker tricked somebody into launching his site when they are in ours, then I guess he could get script to execute in our page.

I don't see any method that takes a COMPLETE url and encodes/escapes JUST the parameters. So for now, I'm tearing down the url, and rebuilding it from the ground up, but encoding the parameter names and values.  This basically prevents the script from running, but I do still end up with at least a javascript error because of

using table variable in single quote



I searched over internet but i couldn't find. How can i use table variable in single quote here some of code that i can do and i can't

for example if i can write like this it will work

declare @table table ([name] varchar(20))
insert into @table values('ahmet')
select * from @table
but if i can write like this does not work
exec('select * from ['+@table+']')
I can use any variable for table name like
declare @tableName varchar(20)
set @tableName = 'sampleTable'
exec('select * from ['+@tableName+

Replacing ampersand and single quote in XSLT


Hi All,

I want to replace single quote and ampersand in XSLT of data view web part.
I tried to use translate function. But when i do a translate of &amp;#39; then &amp; is also getting replaced. Could some one help me on this.


single quote in control.Attributes.Add


I'm trying to add a javascript event on my textbox:


TextBoxTesto.Attributes.Add("onblur", "javascript:onblur_text(this.id, '" & specifictext & "');"))


The rendered html replaces single quotes with "&#39;".

Furthermore I've seen the code of dropdownlist with postback and the rendered html code for them is like this:


onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;controlname\&#39;,\&#39;\&#39;)&#39;, 0)"


This happens with VS 2010 and not VS 2008.

Nevertheless it seems to cause no problem and everything works well, even if I'd prefer to the VS 2008 approach because I'm afraid that some old browser could show some unwanted behaviour.  


how To Insert the single quotes in sqlcommand in asp.net


Hi all

    i am developed on simple user registeration application in that i gave  address field .when i am trying to enter something like this (1st main,b'lore) but wont take while inserting.

my query is

sqlcommand cmd=new sqlcommand("insert into registeration_form(name,address)values('"+txtname.text+"','"+txt_address+"')",con);

how can i pass the  quotes also to my query please if any one know reply me.


G Dinakaran

Generating MS Word doc from mht file gives smart quote problem


I have a word document to be generated using ASP.Net/VB.net.

So I have a word document template saved as .mht file on the web server.

In my ASP.Net code,I read this mht file content and replace certain string line Description$$ with the actual description from the database.Then save this content as .doc file.

This works fine but shows a box symbol when I have smart quotes " (not this one as I cannot type it here.The double quote which you see in MS Word,the slanted double quote).

I dont know how to make my word doc generated, show the exact double quote as in MS word.

If any of you have any idea of this please reply.

Thank you

Problem with ListView and SelectionMode="Single"

  I have the following XAML: <Grid>       <ListView SelectionMode="Single" Height="100" HorizontalAlignment="Left" Margin="26,118,0,0" Name="listBox1" VerticalAlignment="Top" Width="120">       <ListView.View>       <GridView>       <GridViewColumn Header="Test"/>       </GridView>       </ListView.View>       <ListViewItem>Test</ListViewItem>       <ListViewItem>Test</ListViewItem>       <ListViewItem>Test</ListViewItem>       <ListViewItem>Test</ListViewItem>       <ListViewItem>Test</ListViewItem>       <ListViewItem>Test</ListViewItem>       <ListViewItem>Test</ListViewItem>       </ListView>       </Grid>       Just a stock ListView with SelectionMode="Single". Isn't SelectionMode="Single" supposed to be single selection mode? There seems to be a lot of weird stuff with the Ctrl-Key. I tested the same behavior in a standard W

Insert/Update data to multiple tables on a single button click


Hi experts,

I need to insert/update data to 3 or more tables on a single button click.What is best method for achieving this?I am using mysql as my DB.

Thanks for your valuable reply in advance.

Profile synchronization problem - can successfully import single users but not from a group - can yo


I can successfully import a single user into SharePoint 2010 from AD (proves settings permissions are correct) and the number of user profiles increases and I can locate the user including profile data from active Directory. But when I try to import an Active Directory global security group no users get migrated. In fact the single users profile gets deleted.

Can somebody explain whether it is possible to migrate users into SharePoint 2010 from with security groups in Active Directory?

Also when I retried to import the group of users it deleted the single user that I had successfully imported, I didn’t think this was possible, I ran an incremental synchronization, i need to import roughly 2000 users and was going to do it in stages to make sure all users were imported but if the process can remove users then each sync run could be adding users and removing users, how will I ever keep track?

Below is the synchronization run report, are there logs files that could give me more information?

Insert multiple rows with a single INSERT statement


With SQL Server 2005 Express coming out, I have switched from MySql.  I'm having trouble with a very simple INSERT statement that has previously worked in both MySql and Oracle.  The statement is as follows:

INSERT INTO pantscolor_t (procode,color,pic) VALUES
 ('74251', 'Black', '511black.jpg'),
 ('74251', 'Charcoal', '511charcoal.jpg'),
 ('74251', 'Khaki', '511khaki.jpg'),
 ('74251', 'Navy', '511navy.jpg'),
 ('74251', 'OD Green', '511odgreen.jpg');

However, when I attempt to execute this statement with Management Studio Express I get the following error:

Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ','.

Any ideas?

Unable to set up a new Secure Store Service Application in a single-server installation


Problem: after initial SharePoint installation, I tried to add the Secure Store Service Application under "Manager Services Applications".  The process screen returns something like "The time job created.  But failed to start in one or more servers in the farm."  Further investigation found that in the SQL Server, the secure service account was not added under the Login user accounts.  The Secure_Store_Service_DB has been created, but not under the name of secure store service account.  In another word, the database was created but the action seems to be incomplete.

Background: this is a single server farm installation on Windows Server 2008 R2, SQL Server 2008 R2, with AD CS and AD DS, DNS roles enabled on the same box.  The configuration task was running with the farm admin account which is also a domain admin, and has dbcreator, securityadmin, and sysadmin roles in the SQL server.


Problem filling labels with table data outside datalist using single call to db


On a single page, I'd like to fill 2 hyperlink controls as well as a datalist control with table data using one call to the database. The page looks like this:

<div id="PageContent">    
      Please select the district you wish to view below.</p>
      <asp:DropDownList ID="ddlDistrict" runat="server" CssClass="textbox" 
        DataTextField="DistrictName" DataValueField="DistrictId" AutoPostBack="True" 
    <p><asp:label ID="lblDistrictAbbrev" runat="server" Text="District Abbreviation: " />
      <asp:hyperlink ID="hyperlinkDistrictName" runat="server" 
        Text='' NavigateUrl="~/Contact/NationalCouncil.aspx" 
        Font-Bold="True" />
    <p><asp:label ID="lblDistrictCouncillor" runat="server" Text="District Councillor: " />
      <asp:hyperlink ID="hyperlinkCouncillor" runat="server" 
        Text='' NavigateUrl="~/Contact/NationalCouncil.a
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend