Linebreaks in SQLCommand.CommandText (C#)

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Dorte (Dorte_at_discussions.microsoft.com)
Date: 10/21/04


Date: Thu, 21 Oct 2004 04:25:01 -0700

Hi,

>From a C# application I read the SQL text from a text file. The text file
contains line breaks that need to be conserved.

The text file is read by a streamreader and added to a StringBuilder object.
Each line in the text file is read, one at the time. After reading a line, I
add a carriage return/linefeed by System.Enviroment.NewLine. But carriage
returns / linefeeds are added to the StringBuilder as "/r/n". When I add the
content of the StringBuilder object to the SqlCommand.CommandText property
and run the query, the SQL fails.

I have done a similar thing in VB. In VB I added carriage returns/linefeed
by the "vbCrLf" constant. This worked fine. Line breaks were added and
maintained when passing the SQL to the SqlCommand.CommandText property - no
codes were "visible".

I hope someone knows how to handle this in C#.

Thanks,
Dorte



Relevant Pages

  • Re: more about the using statement
    ... TextReader, you probably wouldn't want to keep this line of code as it ... You'd want to declare reader as a StreamReader so that you can take full ... found a lot of places where objects that implement IDisposables are nt being ... StringBuilder object should be employed instead of the string ...
    (microsoft.public.dotnet.languages.csharp)
  • read txtfile into string or stringbuilder or .Net dataTable?
    ... I understand that the stringbuilder object can create a string of text much ... While I'm at it - this data will end up in a .Net dataTable object. ... StreamReader read the data directly into the dataTable? ... Prev by Date: ...
    (microsoft.public.dotnet.languages.vb)