Wednesday, March 21, 2012
Quotes
procedure ?
Ex1: where username = @.username
AND status = "D" -- or 'D'
Ex2: if @.stringtype = "D" -- or 'D'
Select ...............
Thanks.
See "SET QUOTED_IDENTIFIER" in BOL.
Example:
use northwind
go
set quoted_identifier off
go
select 1
where
"1111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111" != '1'
go
set quoted_identifier on
go
select 1
where
"1111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111" != '1'
go
The first "select" statement will return '1', but the second one will give
an error because sql server will consider the string as an identifier.
AMB
"DXC" wrote:
> What is the difference using the single or double quotes in a stored
> procedure ?
> Ex1: where username = @.username
> AND status = "D" -- or 'D'
> Ex2: if @.stringtype = "D" -- or 'D'
> Select ...............
>
> Thanks.
|||Thanks...........
"Alejandro Mesa" wrote:
[vbcol=seagreen]
> See "SET QUOTED_IDENTIFIER" in BOL.
> Example:
> use northwind
> go
> set quoted_identifier off
> go
> select 1
> where
> "1111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111" != '1'
> go
> set quoted_identifier on
> go
> select 1
> where
> "1111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111" != '1'
> go
>
> The first "select" statement will return '1', but the second one will give
> an error because sql server will consider the string as an identifier.
>
> AMB
> "DXC" wrote:
Quotes
procedure ?
Ex1: where username = @.username
AND status = "D" -- or 'D'
Ex2: if @.stringtype = "D" -- or 'D'
Select ...............
Thanks.See "SET QUOTED_IDENTIFIER" in BOL.
Example:
use northwind
go
set quoted_identifier off
go
select 1
where
"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" != '1'
go
set quoted_identifier on
go
select 1
where
"11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" != '1'
go
The first "select" statement will return '1', but the second one will give
an error because sql server will consider the string as an identifier.
AMB
"DXC" wrote:
> What is the difference using the single or double quotes in a stored
> procedure ?
> Ex1: where username = @.username
> AND status = "D" -- or 'D'
> Ex2: if @.stringtype = "D" -- or 'D'
> Select ...............
>
> Thanks.|||Thanks...........
"Alejandro Mesa" wrote:
> See "SET QUOTED_IDENTIFIER" in BOL.
> Example:
> use northwind
> go
> set quoted_identifier off
> go
> select 1
> where
> "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" != '1'
> go
> set quoted_identifier on
> go
> select 1
> where
> "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" != '1'
> go
>
> The first "select" statement will return '1', but the second one will give
> an error because sql server will consider the string as an identifier.
>
> AMB
> "DXC" wrote:
> > What is the difference using the single or double quotes in a stored
> > procedure ?
> >
> > Ex1: where username = @.username
> > AND status = "D" -- or 'D'
> >
> > Ex2: if @.stringtype = "D" -- or 'D'
> > Select ...............
> >
> >
> > Thanks.
Quotes
procedure ?
Ex1: where username = @.username
AND status = "D" -- or 'D'
Ex2: if @.stringtype = "D" -- or 'D'
Select ...............
Thanks.See "SET QUOTED_IDENTIFIER" in BOL.
Example:
use northwind
go
set quoted_identifier off
go
select 1
where
" 1111111111111111111111111111111111111111
11111111111111111111111111111111111
1111111111111111111111111111111111111111
1111111111111" != '1'
go
set quoted_identifier on
go
select 1
where
" 1111111111111111111111111111111111111111
11111111111111111111111111111111111
1111111111111111111111111111111111111111
1111111111111" != '1'
go
The first "select" statement will return '1', but the second one will give
an error because sql server will consider the string as an identifier.
AMB
"DXC" wrote:
> What is the difference using the single or double quotes in a stored
> procedure ?
> Ex1: where username = @.username
> AND status = "D" -- or 'D'
> Ex2: if @.stringtype = "D" -- or 'D'
> Select ...............
>
> Thanks.|||Thanks...........
"Alejandro Mesa" wrote:
[vbcol=seagreen]
> See "SET QUOTED_IDENTIFIER" in BOL.
> Example:
> use northwind
> go
> set quoted_identifier off
> go
> select 1
> where
> " 1111111111111111111111111111111111111111
111111111111111111111111111111111
1111111111111111111111111111111111111111
111111111111111" != '1'
> go
> set quoted_identifier on
> go
> select 1
> where
> " 1111111111111111111111111111111111111111
111111111111111111111111111111111
1111111111111111111111111111111111111111
111111111111111" != '1'
> go
>
> The first "select" statement will return '1', but the second one will give
> an error because sql server will consider the string as an identifier.
>
> AMB
> "DXC" wrote:
>
Tuesday, March 20, 2012
quotation marks in xml
I have a block of xml that I wish to update in my sql database. The problem I have is the the data has double and single quotation marks in it and all my attempts to send this to my sql database gives me errors reguarding the quotation marks. Is there a way I can send the xml to the database without these problems. I am using the xml in the sql database to make it easy to read and right the xml as xmldatasource does not allow reading and writing easily.
this section shows the problem, i am loading xml from a file and trying to insert this into the sql database
XmlTextReader reader = new XmlTextReader(Server.MapPath("xml/wt.xml"));
reader.WhitespaceHandling = WhitespaceHandling.None;
XmlDocument xmlDocF = new XmlDocument();
xmlDocF.Load(reader);
this.SqlDataSource1.UpdateCommand = "update [data] set [linkXML] '" + xmlDocF.InnerXml+ "' where [index] = 1" ;
this.SqlDataSource1.Update();
reader.Close();
pls help
Can you post some part of xml?
<_n0011 HyperLink="undefined" Welcome="A'hneiv zipv meih" Language="undefined" country="undefined" x="1329" y="338"/>
this is an example.
there are about 400 similar tags with about 30 instances of the single quote mark. this may change in the future as i am trying to make the xml editable.
|||I believe using Parameters will take care of the escaping automatically.
|||I have tried the following syntax and got the same problems. I think this type of parameterising just parses the text into the string and produces effectively the same problem. Is there a different type of parameterising that I should be using.
this.SqlDataSource1.UpdateCommand = "update [data] set [linkXML] @.xmlDocF.InnerXml where [index] = 1" ;
I am a bit new to this subject and have looked for an article on this subject but not been able to find anything that deals with this specific requirement.
many thx for your assistance.
|||what kind of parameter method did u have in mind?
|||I created a DataSource with insert/update/delete commands and connected it to a GridView.
In edit mode, I entered this in the AVarCharField: Hello, "test" 'test'
When I clicked update, it worked.
The UpdateCommand looks like this:
UpdateCommand="UPDATE [TestTable] SET [CustomerName] = @.CustomerName, [Status] = @.Status, [AVarCharField] = @.AVarCharField WHERE [ID] = @.ID">The Parameters look like this:
<UpdateParameters> <asp:Parameter Name="CustomerName" Type="String" /> <asp:Parameter Name="Status" Type="Single" /> <asp:Parameter Name="AVarCharField" Type="String" /> <asp:Parameter Name="ID" Type="Int32" /></UpdateParameters>I hope that helps.