473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

simple sql quote problem!

Can someone tell me how I convert this simple SQL statement so I can use it
in ASP.NET???

I have an issue with the quotation marks and wondered if there is a simple
rule for converting the sql statement so if can be used in ASP.NEt!

Thanks

... SQL String

SELECT (CASE WHEN ImgLeft IS NULL THEN '' ELSE '<img src="' + ImgLeft + '"
/> ' END) + [Text] +
(CASE WHEN ImgRight IS NULL THEN '' ELSE ' <img src="' + ImgRight + '" />'
END) AS [Text],
ISNULL(ToolTip, '') AS ToolTip,
ISNULL(Url, '') AS Url,
[ID],
(SELECT COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS
SubMenuItemsCount
FROM APP_Menu A
WHERE Display = 1
AND ParentId = @ParentID
ORDER BY ParentID, DisplayOrder
Nov 19 '05 #1
5 1715
//Replace embedded ' with '' (two single quotes)
string sql = sql.Replace(@"'", @"''");
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Tim::.." wrote:
Can someone tell me how I convert this simple SQL statement so I can use it
in ASP.NET???

I have an issue with the quotation marks and wondered if there is a simple
rule for converting the sql statement so if can be used in ASP.NEt!

Thanks

.. SQL String

SELECT (CASE WHEN ImgLeft IS NULL THEN '' ELSE '<img src="' + ImgLeft + '"
/> ' END) + [Text] +
(CASE WHEN ImgRight IS NULL THEN '' ELSE ' <img src="' + ImgRight + '" />'
END) AS [Text],
ISNULL(ToolTip, '') AS ToolTip,
ISNULL(Url, '') AS Url,
[ID],
(SELECT COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS
SubMenuItemsCount
FROM APP_Menu A
WHERE Display = 1
AND ParentId = @ParentID
ORDER BY ParentID, DisplayOrder

Nov 19 '05 #2
That wasn't exactly my problem!

The problem is I can't get the sql into a string!

This is the closest I got to it!

"SELECT (CASE WHEN ImgLeft IS NULL THEN '' ELSE '<img src='" & Chr(34) &
"ImgLeft" & Chr(34) & "' /> ' END) + [Text] + (CASE WHEN ImgRight IS NULL
THEN '' ELSE ' <img src='" & Chr(34) & "ImgRight" & Chr(34) & "' />' END) AS
Text, ISNULL(ToolTip, '') AS ToolTip, ISNULL(Url, '') AS Url, [ID], (SELECT
COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS SubMenuItemsCount() FROM
APP_Menu A WHERE(Display = 1) AND ParentId = @ParentID ORDER BY ParentID,
DisplayOrder"

Thanks

"Cowboy (Gregory A. Beamer) - MVP" wrote:
//Replace embedded ' with '' (two single quotes)
string sql = sql.Replace(@"'", @"''");
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Tim::.." wrote:
Can someone tell me how I convert this simple SQL statement so I can use it
in ASP.NET???

I have an issue with the quotation marks and wondered if there is a simple
rule for converting the sql statement so if can be used in ASP.NEt!

Thanks

.. SQL String

SELECT (CASE WHEN ImgLeft IS NULL THEN '' ELSE '<img src="' + ImgLeft + '"
/> ' END) + [Text] +
(CASE WHEN ImgRight IS NULL THEN '' ELSE ' <img src="' + ImgRight + '" />'
END) AS [Text],
ISNULL(ToolTip, '') AS ToolTip,
ISNULL(Url, '') AS Url,
[ID],
(SELECT COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS
SubMenuItemsCount
FROM APP_Menu A
WHERE Display = 1
AND ParentId = @ParentID
ORDER BY ParentID, DisplayOrder

Nov 19 '05 #3
> The problem is I can't get the sql into a string!

Looks like a string to me. A String is an array of characters. A String
literal is a sequence of characters enclosed with double quotes. When you
replace the single quotes in it with doubled single quotes, you make it
readable to the database. You should also (as it seems you have) replace
double quotes with CHR(34). When you enclose the whole mess inside a pair of
double quotes, you have a string.

As a side note: You'd be better off leaving all that logic and
string-building out of your SQL Statement. You can replace nulls in your
application with whatever you need. All that logic in a SQL Statement is
going to slow things down.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:7A**********************************@microsof t.com...
That wasn't exactly my problem!

The problem is I can't get the sql into a string!

This is the closest I got to it!

"SELECT (CASE WHEN ImgLeft IS NULL THEN '' ELSE '<img src='" & Chr(34) &
"ImgLeft" & Chr(34) & "' /> ' END) + [Text] + (CASE WHEN ImgRight IS NULL
THEN '' ELSE ' <img src='" & Chr(34) & "ImgRight" & Chr(34) & "' />' END)
AS
Text, ISNULL(ToolTip, '') AS ToolTip, ISNULL(Url, '') AS Url, [ID],
(SELECT
COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS SubMenuItemsCount()
FROM
APP_Menu A WHERE(Display = 1) AND ParentId = @ParentID ORDER BY ParentID,
DisplayOrder"

Thanks

"Cowboy (Gregory A. Beamer) - MVP" wrote:
//Replace embedded ' with '' (two single quotes)
string sql = sql.Replace(@"'", @"''");
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Tim::.." wrote:
> Can someone tell me how I convert this simple SQL statement so I can
> use it
> in ASP.NET???
>
> I have an issue with the quotation marks and wondered if there is a
> simple
> rule for converting the sql statement so if can be used in ASP.NEt!
>
> Thanks
>
> .. SQL String
>
> SELECT (CASE WHEN ImgLeft IS NULL THEN '' ELSE '<img src="' + ImgLeft +
> '"
> /> ' END) + [Text] +
> (CASE WHEN ImgRight IS NULL THEN '' ELSE ' <img src="' + ImgRight + '"
> />'
> END) AS [Text],
> ISNULL(ToolTip, '') AS ToolTip,
> ISNULL(Url, '') AS Url,
> [ID],
> (SELECT COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS
> SubMenuItemsCount
> FROM APP_Menu A
> WHERE Display = 1
> AND ParentId = @ParentID
> ORDER BY ParentID, DisplayOrder

Nov 19 '05 #4
try using a stringbuilder class.

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:A3**********************************@microsof t.com...
Can someone tell me how I convert this simple SQL statement so I can use
it
in ASP.NET???

I have an issue with the quotation marks and wondered if there is a simple
rule for converting the sql statement so if can be used in ASP.NEt!

Thanks

.. SQL String

SELECT (CASE WHEN ImgLeft IS NULL THEN '' ELSE '<img src="' + ImgLeft + '"
/> ' END) + [Text] +
(CASE WHEN ImgRight IS NULL THEN '' ELSE ' <img src="' + ImgRight + '" />'
END) AS [Text],
ISNULL(ToolTip, '') AS ToolTip,
ISNULL(Url, '') AS Url,
[ID],
(SELECT COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS
SubMenuItemsCount
FROM APP_Menu A
WHERE Display = 1
AND ParentId = @ParentID
ORDER BY ParentID, DisplayOrder

Nov 19 '05 #5
Try this:

string sql = "SELECT (CASE WHEN ImgLeft IS NULL THEN '''' ELSE ''<img
src=\"'' + ImgLeft + ''\" /> '' END) + [Text] + (CASE WHEN ImgRight IS NULL
THEN '''' ELSE '' <img src=\"'' + ImgRight + ''\" />'' END) AS
[Text], ISNULL(ToolTip, '''') AS ToolTip, ISNULL(Url, '''') AS
Url, [ID], (SELECT COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS
SubMenuItemsCount FROM APP_Menu A WHERE Display = 1 AND ParentId = @ParentID
ORDER BY ParentID, DisplayOrder)";

or this

System.Text.StringBuilder sql = new System.Text.StringBuilder();

sql.Append("SELECT (CASE WHEN ImgLeft IS NULL THEN '''' ELSE ''<img src=\"''
+ ImgLeft + ''\" /> '' END) + [Text] + (CASE WHEN ImgRight IS NULL THEN ''''
ELSE '' <img src=\"'' + ImgRight + ''\" />'' END) AS [Text], ISNULL(ToolTip,
'''') AS ToolTip, ISNULL(Url, '''') AS Url, [ID], (SELECT COUNT(*) FROM
APP_Menu B WHERE B.ParentID = A.ID) AS SubMenuItemsCount FROM APP_Menu A
WHERE Display = 1 AND ParentId = @ParentID ORDER BY ParentID, DisplayOrder)");
Basically what I did was use the \ (string literal escape) and used '' in
place of any ' as Greg suggested. I do agree with Kevin's statement
regarding the slowness of the sql statement, but that's beyond the scope of
your question.

HTH

Jeff Davis

"Tim::.." wrote:
Can someone tell me how I convert this simple SQL statement so I can use it
in ASP.NET???

I have an issue with the quotation marks and wondered if there is a simple
rule for converting the sql statement so if can be used in ASP.NEt!

Thanks

.. SQL String

SELECT (CASE WHEN ImgLeft IS NULL THEN '' ELSE '<img src="' + ImgLeft + '"
/> ' END) + [Text] +
(CASE WHEN ImgRight IS NULL THEN '' ELSE ' <img src="' + ImgRight + '" />'
END) AS [Text],
ISNULL(ToolTip, '') AS ToolTip,
ISNULL(Url, '') AS Url,
[ID],
(SELECT COUNT(*) FROM APP_Menu B WHERE B.ParentID = A.ID) AS
SubMenuItemsCount
FROM APP_Menu A
WHERE Display = 1
AND ParentId = @ParentID
ORDER BY ParentID, DisplayOrder

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: one man army | last post by:
Hi All- I am new to PHP. I found FAQTS and the php manual. I am trying this sequence, but getting 'no zip string found:'... PHP Version 4.4.0 $doc = new DomDocument; $res =...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
8
by: rdrink | last post by:
I am just getting into pysqlite (with a fair amount of Python and MySQL experience behind me) and have coded a simple test case to try to get the hang of things... yet have run into a 'stock...
3
by: Phillip Vong | last post by:
Using VS2005 w/ simple aspx in VB.net I have a simple databound textbox "LastMtgText" in a formview in the Insert template. All I want to do is make the default date of today when someone goes...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
5
by: Chelong | last post by:
hey,the follow is the text file content ========================================apple====pear== one Lily 7 0 0 7 7 two Lily 20 20 6.6666 20 8 one Lily 0 10 2.85 4 0 two Lily 22 22 7.33326 2 5 ...
7
by: Dustin MacDonald | last post by:
Hi everyone. This is my first time posting to this newsgroup, and although I maintain my netiquette I might've missed something specific to the newsgroup, so hopefully you can avoid flaming me...
5
by: Nightfall | last post by:
Dear friends, consider the following scenario, in Visual Studio 2005 and C# - I create a ASP.NET web service ("server") with a class MyClass and a WebMethod SomeMethod() - I create a client...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.