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!
Dave SPosted Sep 15, 2015, 11:06 AM
Hi
There is no error message. I am trying to create an SP. I am not trying to call it.
@UserID VARCHAR(4) = NULL
@ProjectCode VARCHAR
Manas MohapatraPosted Sep 13, 2015, 9:43 PM
Secondly what is your requirement do you want to create SP or call SP inside data base?
Dave SPosted Sep 13, 2015, 3:10 PM
This doesn't seem to work as the string passed to SQL shows new lines as \r\n which SQL can't understand.
CREATE PROC EXPENSE_ANALYSIS\r\n @UserID VARCHAR(4) = NULL,\r\n
Manas MohapatraPosted Sep 12, 2015, 8:38 AM