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!
Manas MohapatraRank #182 · 13.2K reputationPosted Sep 12, 2015, 4:38 AM EDT
Dave S5 reputationPosted Sep 13, 2015, 11:10 AM EDT
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 MohapatraRank #182 · 13.2K reputationPosted Sep 13, 2015, 5:43 PM EDT
Secondly what is your requirement do you want to create SP or call SP inside data base?
Dave S5 reputationPosted Sep 15, 2015, 7:06 AM EDT
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
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts