473,503 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Carriage Return and Line Feed


Hi All,

I spent too much time on trying to get the CrLf into a string, which
contains embedded SQL statements that can be executed by the
SQLClient.SqlCommand. Note that these SQL statements work fine in VB.Net.
Here is a sample of the code

using System;
namespace MyTest
{ internal class SqlCommandFile
{
public static CrLf = "\r\n";
public static string[] CreateCommands =
{
"IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo]." + CrLf +
"[ORGANIZATION]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)" +
CrLf +
"BEGIN" + CrLf +
" DROP TABLE [ORGANIZATION]" + CrLf +
"END" + CrLf +
" GO",
...... // Next statements....
};
}

In VB.Next, the CrLf would be replaced by vbcrlf and the statements worked
fine. However, in C#, I could not get the SQL statements work because CrLf
(or "\r\n") does not work. During debugging time, I watch the variabe
CreateCommands and noticed that the SQL statements contain exactly the text
"\r\n".

Does anyone know how to solve this carrage return line feed problem so that
the SQL will happy with the embedded statements.
Nov 15 '05 #1
3 127877
David N. <hu******@comcast.net> wrote:
I spent too much time on trying to get the CrLf into a string, which
contains embedded SQL statements that can be executed by the
SQLClient.SqlCommand. Note that these SQL statements work fine in VB.Net.
Here is a sample of the code
<snip>
In VB.Next, the CrLf would be replaced by vbcrlf and the statements worked
fine. However, in C#, I could not get the SQL statements work because CrLf
(or "\r\n") does not work.
What exactly do you mean by "does not work"? What *does* it do?
During debugging time, I watch the variabe
CreateCommands and noticed that the SQL statements contain exactly the text
"\r\n".

Does anyone know how to solve this carrage return line feed problem so that
the SQL will happy with the embedded statements.


Your SQL *does* contain carriage return and line feed - it's just that
the debugger shows them as \r\n so that they're visible. Try writing
them out to the console, or a file, and examine the file.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2

" David N." <hu******@comcast.net> wrote in message
news:OB**************@TK2MSFTNGP10.phx.gbl...
During debugging time, I watch the variabe
CreateCommands and noticed that the SQL statements contain exactly the text "\r\n".


Have you ever debugged any simple string, "blah\r\nblah"? It will appear in
the debugger in the same way. This is because the debugger is trying to show
exactly what characters are in the string. Very handy as some strings
contain only "\n" without the "\r". You'd never know it if the debugger
showed an actual line break instead of the character codes.

Therefore, if the debugger says that a variable contains "\r\n", it means a
line break (CrLf). Otherwise it would show, "\\r\\n".

Regards,
Jon
Nov 15 '05 #3
Hi David,

I quickly tested out the code you have provided in a console app and it seemed
to work fine. What is the problem that you are seeing? Can you test this out
and by the way, CrLf variable is not declared as string in your code but I
changed it.

namespace ConTest
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
///
public static string CrLf = "\r\n";
public static string[] CreateCommands = {
"IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo]."
+ CrLf +
"[ORGANIZATION]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)" +
CrLf +
"BEGIN" + CrLf +
" DROP TABLE [ORGANIZATION]" + CrLf +
"END" + CrLf +
" GO",
" Second arguement to array." // Next statements....
};

[STAThread]
static void Main(string[] args)
{
Console.WriteLine(CreateCommands[0].ToString());
Console.WriteLine("Hit Enter to Close");
Console.ReadLine(); // Wait for user input

}
}
}
Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.

Nov 15 '05 #4

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

Similar topics

6
31210
by: | last post by:
Hi, I want to send an Email using ASP (I know how to to this) The body of the Email contains several variabels How do I concat string values and separate them by carriage returns/ Line feeds? ...
1
2194
by: Neil S. | last post by:
I am writing an ISAPI filter which is using CAPICOM to encrypt and decrypt cookie information. I've found that the encryption string being returned by CAPICOM a has carriage control and line feed....
1
850
by: wschaub | last post by:
Is there any way of forcing an ASMX web service not to translate a carriage return – line feed (\r\n) with a (\n\n), in other words the carriage return \r is replaced with a \n if contained as...
2
38736
by: John Dalberg | last post by:
Hi What's the regex to remove the carriage return/line field from a string? These can occur multiple times in the string as in xxx\r\n\r\n. -- John Dalberg
2
18750
by: Torsten Zachert | last post by:
I would like to insert some text with embedded carriage return/line feed into a MS Access text field with OleDb and C# ADO.NET. I tried to use "\n" in combination with "\r". If I display the input...
0
1098
by: John Dalberg | last post by:
I noticed that when I add key/value pairs to a NameValueCollection variable and send this collection through a POST using WebClient.UploadValues method, the recepient process receives the...
0
1805
by: J.Marsch | last post by:
I am having a problem in which ASP.Net web services are corrupting my data. I know that my problem is related to the standard way of encoding carriage return linefeeds, so I need to figure out how...
2
900
by: Enrico Sabbadin | last post by:
Hi, A few days go I fiund iut that the xmlserializer strips away /r/n out during deserialization (and just leave /n) ... I found out that you can resolve this problem using the deserialize...
8
19763
by: kcovert | last post by:
using System.Net.Mail; I've been unable to get a carriage return/line feed into the body of my Outlook message. Have look all over the web for a soltion with no luck. Here's what I have tried...
0
1778
by: Hayduke | last post by:
I've observed various posts here and elsewhere concerning CRLFs getting stripped out of programatically generated emails. This behavior is evident when the email is viewed using various versions of...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
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...
0
7453
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...
1
5005
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
4670
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
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.