Dave S

Dave S

  • NA
  • 5
  • 684

How to create an SQL SP with C# with line breaks

Sep 12 2015 4:49 AM

Hi all

 

I’m a newbie to C# so be gentle!  I do however work a lot with SQL and I’ve been trying to use C# to link to SQL.  On the whole I am getting on ok but I have this issue.  In some ways it’s not a major issue as everything works, it’s more to please my OCD (and to make it easier to modify in SQL).

 

The code below creates an SP in my database however it creates it as a single line.  This makes editing it a pain in SQL.  I have tried to embed CHAR(13) in it but it doesn’t want to play ball!

 

Can anyone tell me how I can do this (preferably without changing the way I issue commands to SQL)

 

 

string Deft = "";

SqlConnection conn = new SqlConnection(Logon.SQLConn);

conn.Open();

 

CommandText = " CREATE PROC EXPENSE_ANALYSIS” +

“ @UserID    VARCHAR(4) = NULL,”+

“ @ProjectCode   VARCHAR(10) = NULL  " +             +

“ SET @ AnalysisCode=’ABC’ “  +

“IF LEFT(@ProjectCode,1)=’A’ SET @AnalysisCode =’123’” +

“SELECT @AnalysisCode ";  

 

command = new SqlCommand(CommandText, conn);

Deft = (string)command.ExecuteScalar();

 

Thanks in Advance!


Answers (4)