Linebreak in C# SqlCommand.CommandText makes SQL fail

G

Guest

Hi,

I am using ADO.NET in a C# application to get data from a SQL Server 2000.
The SqlCommand.CommandText is read from a text file.

The text file with the Sql query contains line breaks that need to be
conserved.
The CommandText should contain several SQL queries and "GO's" - all read
from the text file. The "Go" command needs a linebreak, otherwise the sql
fails.

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 for linebreaks etc. were "visible".

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

Thanks,
Dorte
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top