Friday, March 30, 2012

Inserting " ' "

Hello,
I have a text field which consists of strings. And I want to insert
whatever the user types into the database. But if the user types some
punctuation marks, such as " ' ", it generates this error:
Unclosed quotation mark after the character string ')'.
the solutions should be so easy, but I couldn't find out where the
close it.
my update command is as follows:
sqlDS.InsertCommand = "INSERT INTO Table VALUES('" & User.Identity.Name
& "','" & Today.Date & "','" & TextBox1.Text & "','" & TextBox2.Text &
"','" & Today.Now & "','Y')"Hi
Add one more "'"
CREATE TABLE #Test (c VARCHAR(10))
INSERT INTO #Test VALUES ('O'' Connor')
"Dot Net Daddy" <cagriandac@.gmail.com> wrote in message
news:1155534287.413841.202530@.m79g2000cwm.googlegroups.com...
> Hello,
> I have a text field which consists of strings. And I want to insert
> whatever the user types into the database. But if the user types some
> punctuation marks, such as " ' ", it generates this error:
>
> Unclosed quotation mark after the character string ')'.
> the solutions should be so easy, but I couldn't find out where the
> close it.
> my update command is as follows:
> sqlDS.InsertCommand = "INSERT INTO Table VALUES('" & User.Identity.Name
> & "','" & Today.Date & "','" & TextBox1.Text & "','" & TextBox2.Text &
> "','" & Today.Now & "','Y')"
>|||This really isn't a SQL question because you need to know how to do
this in VB.NET before the query is passed to the database.
You would do this:
> sqlDS.InsertCommand = "INSERT INTO Table VALUES('" & User.Identity.Name
> & "','" & Today.Date & "','" & TextBox1.Text.Replace("'","''") & "','" & TextBox2.Text.Replace("'","''") &
> "','" & Today.Now & "','Y')"
Izzy
Dot Net Daddy wrote:
> Hello,
> I have a text field which consists of strings. And I want to insert
> whatever the user types into the database. But if the user types some
> punctuation marks, such as " ' ", it generates this error:
>
> Unclosed quotation mark after the character string ')'.
> the solutions should be so easy, but I couldn't find out where the
> close it.
> my update command is as follows:
> sqlDS.InsertCommand = "INSERT INTO Table VALUES('" & User.Identity.Name
> & "','" & Today.Date & "','" & TextBox1.Text & "','" & TextBox2.Text &
> "','" & Today.Now & "','Y')"|||Thank you for your helps.
Izzy wrote:
> This really isn't a SQL question because you need to know how to do
> this in VB.NET before the query is passed to the database.
> You would do this:
> > sqlDS.InsertCommand = "INSERT INTO Table VALUES('" & User.Identity.Name
> > & "','" & Today.Date & "','" & TextBox1.Text.Replace("'","''") & "','" & TextBox2.Text.Replace("'","''") &
> > "','" & Today.Now & "','Y')"
> Izzy
>
> Dot Net Daddy wrote:
> > Hello,
> >
> > I have a text field which consists of strings. And I want to insert
> > whatever the user types into the database. But if the user types some
> > punctuation marks, such as " ' ", it generates this error:
> >
> >
> > Unclosed quotation mark after the character string ')'.
> >
> > the solutions should be so easy, but I couldn't find out where the
> > close it.
> >
> > my update command is as follows:
> >
> > sqlDS.InsertCommand = "INSERT INTO Table VALUES('" & User.Identity.Name
> > & "','" & Today.Date & "','" & TextBox1.Text & "','" & TextBox2.Text &
> > "','" & Today.Now & "','Y')"sql

No comments:

Post a Comment