D
David N.
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.
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.