473,471 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Carriage Return and String confusion...

I am preparing the text of a stored procedure using StringBuilder but
bumps into \r\n issues...

I use some syntax like

MyStringBuilder.Append("Something very clever here");
MyStringBuilder.Append("\r\nGO");

If I then write MyStringBuilder.ToString() into a file, it's perfect as
I have in my file

Something very clever here
GO

Great!

However, if I try to send the content of MyStringBuilder.ToString()
directly to the database engine (SQL Server), it does not work because
the "\r" and "\n" are not interpreted as Carriage Return Line Feed but
merely as "\" followed by "r" or "n"...

Another symptom of the same problem seems to be that if I run this in a
VB.Net debug window

?String.Format("*{0}*", chr(13))

I get

"*
*"

but I don't manage to do it in C#

?String.Format("*{0}*", (char)13)

gives

"*\r*"

Can somebody explain this to me, please?

Nov 17 '05 #1
4 12035
However, if I try to send the content of MyStringBuilder.ToString()
directly to the database engine (SQL Server), it does not work because
the "\r" and "\n" are not interpreted as Carriage Return Line Feed but
merely as "\" followed by "r" or "n"...
What makes you think that?

?String.Format("*{0}*", (char)13)

gives

"*\r*"

Can somebody explain this to me, please?


It's a debugger "feature". It shows strings the way you'd write them
as literals in your code, rather than how they would be printed.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #2
Mattias Sjögren wrote:
However, if I try to send the content of MyStringBuilder.ToString()
directly to the database engine (SQL Server), it does not work becausethe "\r" and "\n" are not interpreted as Carriage Return Line Feed butmerely as "\" followed by "r" or "n"...


What makes you think that?

Well, the goal is to generate some Stored Procedure and store the sql
script in a file (for source control).

My scripts always have the same pattern, which is

IF (...)
DROP PROCEDURE ...
GO
CREATE PROCEDURE ...
....
GO

I generate the SQL script using a Stringbuilder, MySB, and extract the
final sql using

String sql = MySB.ToString();

If I use the sql string to run it straight against the database, it
fails
with "incorrect syntax near 'GO'"

If I run the script through Query Analyzer, then it works without
problem.

This is the first time I try to do this in C# while I have done it many
times in VB.Net using vbCRLF without problem.

Nov 17 '05 #3
Hi,
Just remove GO... it will work.

Kishor
kpise@hot****.com
"Eric Le Bouffon" wrote:
Mattias Sjögren wrote:
However, if I try to send the content of MyStringBuilder.ToString()
directly to the database engine (SQL Server), it does not work becausethe "\r" and "\n" are not interpreted as Carriage Return Line Feed butmerely as "\" followed by "r" or "n"...


What makes you think that?

Well, the goal is to generate some Stored Procedure and store the sql
script in a file (for source control).

My scripts always have the same pattern, which is

IF (...)
DROP PROCEDURE ...
GO
CREATE PROCEDURE ...
....
GO

I generate the SQL script using a Stringbuilder, MySB, and extract the
final sql using

String sql = MySB.ToString();

If I use the sql string to run it straight against the database, it
fails
with "incorrect syntax near 'GO'"

If I run the script through Query Analyzer, then it works without
problem.

This is the first time I try to do this in C# while I have done it many
times in VB.Net using vbCRLF without problem.

Nov 17 '05 #4
Stupid me...

I must just send these batches separaty.

Nov 17 '05 #5

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

Similar topics

3
by: Charles Gamble | last post by:
Hi, I am performing a post from one classic ASP page to another in order to get the value of a string passed between the two pages. I have a client script variable declared to take the value of...
2
by: Alin Popovici | last post by:
Hi! I have this problem. I am sending as a parameter for a webmethod a string containing '\r\n' sequences. For some reason, when I debug my webmethod, the paramter is received with the carriage...
2
by: Andrew Chanter | last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 & vbcr & Item3 This works as planned in the...
5
by: Chad Paquette | last post by:
Hi, We have a legacy cgi app that's written in C. We are encountering an error when we try to retrieve a cgi environment variable. The variable we are getting contains a Base64 encoded...
2
by: sean | last post by:
Can anyone tell me how to add a carriage return to a string using vb.net? I need to add two strings with a carrage return together and post to an email message body ie: This gives me an...
2
by: sys | last post by:
I have a web method that returns a string. When I return a string that has a carriage return and line feed in it ("\r\n") on the client side I only receive a string including the line feed ("\n")....
11
by: TheRain | last post by:
Hi, I am trying to append a carriage return to my string using the string builder class, but when I do this the string ends up containing "13". I tried this multiple ways like so ...
3
by: Dinsdale | last post by:
I have an xml file that is read into an object using serialization. One of the objects has a string field called delimeter that I want to contain a carriage return. Instead of trying to include the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.