[RESOLVED] SQL INSERT with apostrophes
I am coding in Visual Basic .NET, and using Visual Studio .NET 2003. I am working with SQL Server 2005 Express.
I'm trying to insert strings among other things into a database I have created. The problem is when I try to insert a string with an apostrophe in it (i.e. "Let's go") I'm having issues because the SQL command ends up looking something like this:
INSERT INTO table1('Let's go')
As you can see the apostrophe messes up my quotes, I've tried using double quotes but they won't work :/
I was looking into converting the string into unicode or something similar, but is there an easier way around this?
Re: [02/03] SQL INSERT with apostrophes
Don't use double-quotes, use two single-quotes. ;)
Code:
INSERT INTO table1('Let''s go')
(I'm afraid I dont know the .Net code to add the extra single quote)
Re: [02/03] SQL INSERT with apostrophes
stringname.replace("'","''")
Or just use parameterized queries/stored procs.
Re: [02/03] SQL INSERT with apostrophes
thanks I used the replace method for now. I don't know if parameterized queries could apply to what I'm doing, but I'll do more research on them when I'm going over this with a fine tooth comb.
Thanks again! :)