PC Review


Reply
Thread Tools Rate Thread

What Did I Miss Here?

 
 
Wayne Wengert
Guest
Posts: n/a
 
      11th Sep 2004
I am using VB.NET connected to an SQL 2000 server and I want to save some
text fields from a form to string fields in a table. The text might include
some single quotes so in my update command I am replacing single quotes with
two single quotes so that the update query works. (see piece of statement
below)

My problem is that when I look at what really gets stored in the table, all
single quotes are now doubled such as:

Text Value = Joe's
Stored in table = Joe''s

What am I missing here?


============ Segment of SQL statement =============


Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text, "'", "''")
& "',.....


 
Reply With Quote
 
 
 
 
Hermit Dave
Guest
Posts: n/a
 
      11th Sep 2004
instead of using two single quotes try and parameterize your query.

ie using SqlParameter
ideal way is to use SqlParameters with stored procedures but they can be
used with plain old inserts / updates

look it up

with parameters you dont need to fix the quotes before inserting them

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am using VB.NET connected to an SQL 2000 server and I want to save some
> text fields from a form to string fields in a table. The text might

include
> some single quotes so in my update command I am replacing single quotes

with
> two single quotes so that the update query works. (see piece of statement
> below)
>
> My problem is that when I look at what really gets stored in the table,

all
> single quotes are now doubled such as:
>
> Text Value = Joe's
> Stored in table = Joe''s
>
> What am I missing here?
>
>
> ============ Segment of SQL statement =============
>
>
> Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text, "'",

"''")
> & "',.....
>
>



 
Reply With Quote
 
Jared
Guest
Posts: n/a
 
      11th Sep 2004
Have you tried to execute your function without replacing your quotes? Does
it produce the results you want? Is possible that your dataadapter or
whatever you are using escapes this char for you? I know the xmldocument
object does this intrinsically.

obj.innerText = "Amos & Andrew"
- Produces -
<obj>Amos &amp; Andrew</obj>


"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I am using VB.NET connected to an SQL 2000 server and I want to save some
> text fields from a form to string fields in a table. The text might
> include
> some single quotes so in my update command I am replacing single quotes
> with
> two single quotes so that the update query works. (see piece of statement
> below)
>
> My problem is that when I look at what really gets stored in the table,
> all
> single quotes are now doubled such as:
>
> Text Value = Joe's
> Stored in table = Joe''s
>
> What am I missing here?
>
>
> ============ Segment of SQL statement =============
>
>
> Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text, "'",
> "''")
> & "',.....
>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      11th Sep 2004
Thanks Hermit. I'll try that approach but I am still confused as to why the
replace approach doesn't work. I stopped the app and displayed the sql
string with the doubled instances of a single quote. If I copy/past that
into QA and run it, it works as expected but when run from my ASP app, it
stored the doubled single quotes?

Wayne

"Hermit Dave" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> instead of using two single quotes try and parameterize your query.
>
> ie using SqlParameter
> ideal way is to use SqlParameters with stored procedures but they can be
> used with plain old inserts / updates
>
> look it up
>
> with parameters you dont need to fix the quotes before inserting them
>
> --
>
> Regards,
>
> Hermit Dave
> (http://hdave.blogspot.com)
> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I am using VB.NET connected to an SQL 2000 server and I want to save

some
> > text fields from a form to string fields in a table. The text might

> include
> > some single quotes so in my update command I am replacing single quotes

> with
> > two single quotes so that the update query works. (see piece of

statement
> > below)
> >
> > My problem is that when I look at what really gets stored in the table,

> all
> > single quotes are now doubled such as:
> >
> > Text Value = Joe's
> > Stored in table = Joe''s
> >
> > What am I missing here?
> >
> >
> > ============ Segment of SQL statement =============
> >
> >
> > Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text, "'",

> "''")
> > & "',.....
> >
> >

>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      11th Sep 2004
Jared;

Thanks for the reply. If I don't use the replace function the sql statement
blows up!

Wayne

"Jared" <@(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Have you tried to execute your function without replacing your quotes?

Does
> it produce the results you want? Is possible that your dataadapter or
> whatever you are using escapes this char for you? I know the xmldocument
> object does this intrinsically.
>
> obj.innerText = "Amos & Andrew"
> - Produces -
> <obj>Amos &amp; Andrew</obj>
>
>
> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I am using VB.NET connected to an SQL 2000 server and I want to save some
> > text fields from a form to string fields in a table. The text might
> > include
> > some single quotes so in my update command I am replacing single quotes
> > with
> > two single quotes so that the update query works. (see piece of

statement
> > below)
> >
> > My problem is that when I look at what really gets stored in the table,
> > all
> > single quotes are now doubled such as:
> >
> > Text Value = Joe's
> > Stored in table = Joe''s
> >
> > What am I missing here?
> >
> >
> > ============ Segment of SQL statement =============
> >
> >
> > Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text, "'",
> > "''")
> > & "',.....
> >
> >

>
>



 
Reply With Quote
 
Jared
Guest
Posts: n/a
 
      11th Sep 2004
In the database is it stored with two single quotes '' or one double quote
"? Could you have mistyped the replacement string? All the documentation
I've found supports your method. Could it have something to do with your
colation?
If you paste this block into query analyzer what does it produce?

CREATE TABLE #MyTable (
Col1 varchar(25),
Col2 varchar(25))

INSERT INTO #MyTable VALUES('it''s a boy', 'it''s a girl')
SELECT * FROM #MyTable
DROP TABLE #MyTable

"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Jared;
>
> Thanks for the reply. If I don't use the replace function the sql
> statement
> blows up!
>
> Wayne
>
> "Jared" <@(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Have you tried to execute your function without replacing your quotes?

> Does
>> it produce the results you want? Is possible that your dataadapter or
>> whatever you are using escapes this char for you? I know the xmldocument
>> object does this intrinsically.
>>
>> obj.innerText = "Amos & Andrew"
>> - Produces -
>> <obj>Amos &amp; Andrew</obj>
>>
>>
>> "Wayne Wengert" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >I am using VB.NET connected to an SQL 2000 server and I want to save
>> >some
>> > text fields from a form to string fields in a table. The text might
>> > include
>> > some single quotes so in my update command I am replacing single quotes
>> > with
>> > two single quotes so that the update query works. (see piece of

> statement
>> > below)
>> >
>> > My problem is that when I look at what really gets stored in the table,
>> > all
>> > single quotes are now doubled such as:
>> >
>> > Text Value = Joe's
>> > Stored in table = Joe''s
>> >
>> > What am I missing here?
>> >
>> >
>> > ============ Segment of SQL statement =============
>> >
>> >
>> > Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text, "'",
>> > "''")
>> > & "',.....
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      11th Sep 2004
In the database it is being stored as two single quotes. I've verified that
I really am typing two single quotes and when I run your sample in QA it
works as expected (it's a boy it's a girl)

I've used this replace method many times in ASP and it has always worked
fine. I am wondering if there is something special in .NET?

Wayne

"Jared" <@(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In the database is it stored with two single quotes '' or one double quote
> "? Could you have mistyped the replacement string? All the documentation
> I've found supports your method. Could it have something to do with your
> colation?
> If you paste this block into query analyzer what does it produce?
>
> CREATE TABLE #MyTable (
> Col1 varchar(25),
> Col2 varchar(25))
>
> INSERT INTO #MyTable VALUES('it''s a boy', 'it''s a girl')
> SELECT * FROM #MyTable
> DROP TABLE #MyTable
>
> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Jared;
> >
> > Thanks for the reply. If I don't use the replace function the sql
> > statement
> > blows up!
> >
> > Wayne
> >
> > "Jared" <@(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> Have you tried to execute your function without replacing your quotes?

> > Does
> >> it produce the results you want? Is possible that your dataadapter or
> >> whatever you are using escapes this char for you? I know the

xmldocument
> >> object does this intrinsically.
> >>
> >> obj.innerText = "Amos & Andrew"
> >> - Produces -
> >> <obj>Amos &amp; Andrew</obj>
> >>
> >>
> >> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> >I am using VB.NET connected to an SQL 2000 server and I want to save
> >> >some
> >> > text fields from a form to string fields in a table. The text might
> >> > include
> >> > some single quotes so in my update command I am replacing single

quotes
> >> > with
> >> > two single quotes so that the update query works. (see piece of

> > statement
> >> > below)
> >> >
> >> > My problem is that when I look at what really gets stored in the

table,
> >> > all
> >> > single quotes are now doubled such as:
> >> >
> >> > Text Value = Joe's
> >> > Stored in table = Joe''s
> >> >
> >> > What am I missing here?
> >> >
> >> >
> >> > ============ Segment of SQL statement =============
> >> >
> >> >
> >> > Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text,

"'",
> >> > "''")
> >> > & "',.....
> >> >
> >> >
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Jared
Guest
Posts: n/a
 
      11th Sep 2004
Is the Use Quoted Identifiers option checked in your database property sheet
under the Options tab?

"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In the database it is being stored as two single quotes. I've verified
> that
> I really am typing two single quotes and when I run your sample in QA it
> works as expected (it's a boy it's a girl)
>
> I've used this replace method many times in ASP and it has always worked
> fine. I am wondering if there is something special in .NET?
>
> Wayne
>
> "Jared" <@(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> In the database is it stored with two single quotes '' or one double
>> quote
>> "? Could you have mistyped the replacement string? All the documentation
>> I've found supports your method. Could it have something to do with your
>> colation?
>> If you paste this block into query analyzer what does it produce?
>>
>> CREATE TABLE #MyTable (
>> Col1 varchar(25),
>> Col2 varchar(25))
>>
>> INSERT INTO #MyTable VALUES('it''s a boy', 'it''s a girl')
>> SELECT * FROM #MyTable
>> DROP TABLE #MyTable
>>
>> "Wayne Wengert" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Jared;
>> >
>> > Thanks for the reply. If I don't use the replace function the sql
>> > statement
>> > blows up!
>> >
>> > Wayne
>> >
>> > "Jared" <@(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> Have you tried to execute your function without replacing your quotes?
>> > Does
>> >> it produce the results you want? Is possible that your dataadapter or
>> >> whatever you are using escapes this char for you? I know the

> xmldocument
>> >> object does this intrinsically.
>> >>
>> >> obj.innerText = "Amos & Andrew"
>> >> - Produces -
>> >> <obj>Amos &amp; Andrew</obj>
>> >>
>> >>
>> >> "Wayne Wengert" <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed)...
>> >> >I am using VB.NET connected to an SQL 2000 server and I want to save
>> >> >some
>> >> > text fields from a form to string fields in a table. The text might
>> >> > include
>> >> > some single quotes so in my update command I am replacing single

> quotes
>> >> > with
>> >> > two single quotes so that the update query works. (see piece of
>> > statement
>> >> > below)
>> >> >
>> >> > My problem is that when I look at what really gets stored in the

> table,
>> >> > all
>> >> > single quotes are now doubled such as:
>> >> >
>> >> > Text Value = Joe's
>> >> > Stored in table = Joe''s
>> >> >
>> >> > What am I missing here?
>> >> >
>> >> >
>> >> > ============ Segment of SQL statement =============
>> >> >
>> >> >
>> >> > Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text,

> "'",
>> >> > "''")
>> >> > & "',.....
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
Wayne Wengert
Guest
Posts: n/a
 
      11th Sep 2004
Jared;

Exactly where is this database property sheet? I'm not sure I understand
what you are referring to?

Wayne

"Jared" <@(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is the Use Quoted Identifiers option checked in your database property

sheet
> under the Options tab?
>
> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > In the database it is being stored as two single quotes. I've verified
> > that
> > I really am typing two single quotes and when I run your sample in QA it
> > works as expected (it's a boy it's a girl)
> >
> > I've used this replace method many times in ASP and it has always worked
> > fine. I am wondering if there is something special in .NET?
> >
> > Wayne
> >
> > "Jared" <@(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> In the database is it stored with two single quotes '' or one double
> >> quote
> >> "? Could you have mistyped the replacement string? All the

documentation
> >> I've found supports your method. Could it have something to do with

your
> >> colation?
> >> If you paste this block into query analyzer what does it produce?
> >>
> >> CREATE TABLE #MyTable (
> >> Col1 varchar(25),
> >> Col2 varchar(25))
> >>
> >> INSERT INTO #MyTable VALUES('it''s a boy', 'it''s a girl')
> >> SELECT * FROM #MyTable
> >> DROP TABLE #MyTable
> >>
> >> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > Jared;
> >> >
> >> > Thanks for the reply. If I don't use the replace function the sql
> >> > statement
> >> > blows up!
> >> >
> >> > Wayne
> >> >
> >> > "Jared" <@(E-Mail Removed)> wrote in message
> >> > news:(E-Mail Removed)...
> >> >> Have you tried to execute your function without replacing your

quotes?
> >> > Does
> >> >> it produce the results you want? Is possible that your dataadapter

or
> >> >> whatever you are using escapes this char for you? I know the

> > xmldocument
> >> >> object does this intrinsically.
> >> >>
> >> >> obj.innerText = "Amos & Andrew"
> >> >> - Produces -
> >> >> <obj>Amos &amp; Andrew</obj>
> >> >>
> >> >>
> >> >> "Wayne Wengert" <(E-Mail Removed)> wrote in message
> >> >> news:(E-Mail Removed)...
> >> >> >I am using VB.NET connected to an SQL 2000 server and I want to

save
> >> >> >some
> >> >> > text fields from a form to string fields in a table. The text

might
> >> >> > include
> >> >> > some single quotes so in my update command I am replacing single

> > quotes
> >> >> > with
> >> >> > two single quotes so that the update query works. (see piece of
> >> > statement
> >> >> > below)
> >> >> >
> >> >> > My problem is that when I look at what really gets stored in the

> > table,
> >> >> > all
> >> >> > single quotes are now doubled such as:
> >> >> >
> >> >> > Text Value = Joe's
> >> >> > Stored in table = Joe''s
> >> >> >
> >> >> > What am I missing here?
> >> >> >
> >> >> >
> >> >> > ============ Segment of SQL statement =============
> >> >> >
> >> >> >
> >> >> > Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text,

> > "'",
> >> >> > "''")
> >> >> > & "',.....
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>

> >
> >

>
>



 
Reply With Quote
 
Jared
Guest
Posts: n/a
 
      12th Sep 2004
In Enterprise manager, right click on the database, choose properties, look
on the options tab, there is a check box specifying the use of quoted
identifiers. You will have to do a little more reasearch on what this
actually does, sql server books online has a pretty lengthy article on it.

I found this article as well, I didn't get a chance to read it all, but, it
looked like it had some relevance.
http://support.microsoft.com/default...NoWebContent=1

"Wayne Wengert" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Jared;
>
> Exactly where is this database property sheet? I'm not sure I understand
> what you are referring to?
>
> Wayne
>
> "Jared" <@(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Is the Use Quoted Identifiers option checked in your database property

> sheet
>> under the Options tab?
>>
>> "Wayne Wengert" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > In the database it is being stored as two single quotes. I've verified
>> > that
>> > I really am typing two single quotes and when I run your sample in QA
>> > it
>> > works as expected (it's a boy it's a girl)
>> >
>> > I've used this replace method many times in ASP and it has always
>> > worked
>> > fine. I am wondering if there is something special in .NET?
>> >
>> > Wayne
>> >
>> > "Jared" <@(E-Mail Removed)> wrote in message
>> > news:(E-Mail Removed)...
>> >> In the database is it stored with two single quotes '' or one double
>> >> quote
>> >> "? Could you have mistyped the replacement string? All the

> documentation
>> >> I've found supports your method. Could it have something to do with

> your
>> >> colation?
>> >> If you paste this block into query analyzer what does it produce?
>> >>
>> >> CREATE TABLE #MyTable (
>> >> Col1 varchar(25),
>> >> Col2 varchar(25))
>> >>
>> >> INSERT INTO #MyTable VALUES('it''s a boy', 'it''s a girl')
>> >> SELECT * FROM #MyTable
>> >> DROP TABLE #MyTable
>> >>
>> >> "Wayne Wengert" <(E-Mail Removed)> wrote in message
>> >> news:(E-Mail Removed)...
>> >> > Jared;
>> >> >
>> >> > Thanks for the reply. If I don't use the replace function the sql
>> >> > statement
>> >> > blows up!
>> >> >
>> >> > Wayne
>> >> >
>> >> > "Jared" <@(E-Mail Removed)> wrote in message
>> >> > news:(E-Mail Removed)...
>> >> >> Have you tried to execute your function without replacing your

> quotes?
>> >> > Does
>> >> >> it produce the results you want? Is possible that your dataadapter

> or
>> >> >> whatever you are using escapes this char for you? I know the
>> > xmldocument
>> >> >> object does this intrinsically.
>> >> >>
>> >> >> obj.innerText = "Amos & Andrew"
>> >> >> - Produces -
>> >> >> <obj>Amos &amp; Andrew</obj>
>> >> >>
>> >> >>
>> >> >> "Wayne Wengert" <(E-Mail Removed)> wrote in message
>> >> >> news:(E-Mail Removed)...
>> >> >> >I am using VB.NET connected to an SQL 2000 server and I want to

> save
>> >> >> >some
>> >> >> > text fields from a form to string fields in a table. The text

> might
>> >> >> > include
>> >> >> > some single quotes so in my update command I am replacing single
>> > quotes
>> >> >> > with
>> >> >> > two single quotes so that the update query works. (see piece of
>> >> > statement
>> >> >> > below)
>> >> >> >
>> >> >> > My problem is that when I look at what really gets stored in the
>> > table,
>> >> >> > all
>> >> >> > single quotes are now doubled such as:
>> >> >> >
>> >> >> > Text Value = Joe's
>> >> >> > Stored in table = Joe''s
>> >> >> >
>> >> >> > What am I missing here?
>> >> >> >
>> >> >> >
>> >> >> > ============ Segment of SQL statement =============
>> >> >> >
>> >> >> >
>> >> >> > Update UnitShowInfo Set ShowName = '" & Replace(txtShowName.Text,
>> > "'",
>> >> >> > "''")
>> >> >> > & "',.....
>> >> >> >
>> >> >> >
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Do you miss me?? Mick Murphy Windows Vista General Discussion 1 9th Sep 2008 01:15 AM
Re: Do you miss me?? Mick Murphy Windows Vista Networking 1 9th Sep 2008 01:15 AM
Re: Do you miss me?? Mick Murphy Windows Vista Installation 0 9th Sep 2008 12:17 AM
Re: Do you miss me?? The Hornet Windows Vista Security 0 8th Sep 2008 01:19 PM
RAM EWF on CF hit and miss David D Windows XP Embedded 30 19th Feb 2004 11:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:28 AM.