I am attempting to run a stored procedure using the following C# code
int intHowMany = docType.Count;
switch(intHowMany)
{
case 1:
string returntype1 = "'" + docType.ElementAt(0) + "'";
return returntype1;
case 2:
string returntype2 = "'" + docType.ElementAt(0) + "',"
+ "'" + docType.ElementAt(1) + "'";
return returntype2;
case 3:
string returntype3 = "'" + docType.ElementAt(0) + "',"
+ "'" + docType.ElementAt(1) + "',"
+ "'" + docType.ElementAt(2) + "'";
return returntype3;
case 4:
string returntype4 = "'"+docType.ElementAt(0)+"',"
+"'"+ docType.ElementAt(1)+"',"
+"'"+ docType.ElementAt(2)+"',"
+"'"+docType.ElementAt(3)+"'";
return returntype4;
case 5:
string returntype5 = "'" + docType.ElementAt(0) + "',"
+ "'" + docType.ElementAt(1)+"',"
+ "'" + docType.ElementAt(2)+"',"
+ "'" + docType.ElementAt(3)+"'"+","
+ "'" + docType.ElementAt(4)+"'";
return returntype5;
case 6:
string returntype6 = "'" + docType.ElementAt(0) + "',"
+ "'" + docType.ElementAt(1) + "',"
+ "'" + docType.ElementAt(2)
+ "'," + "'" + docType.ElementAt(3)
+ "'," + "'" + docType.ElementAt(4)
+ "'," + "'" + docType.ElementAt(5) +"'";
return returntype6;
case 7:
string returntype7 = "'"
+ docType.ElementAt(0) + "',"
+ "'" + docType.ElementAt(1) + "',"
+ "'" + docType.ElementAt(2) + "',"
+ "'" + docType.ElementAt(3) + "',"
+ "'" + docType.ElementAt(4) + "',"
+ "'" + docType.ElementAt(5) + "',"
+ "'" + docType.ElementAt(6) + "'";
return returntype7;
break;
}
return null;
}
The above code provides the data for a SQL parameter that completes a SQL WHERE CloumnsName IN() statement.
The case statements for 1, 2 and 3 work as expected. However case statements 4 thru 7 fail with the following error message:
Unclosed quotation mark after the character string 'LA)) order by inc_date_recvd desc;'. Incorrect syntax near 'LA)) order by inc_date_recvd desc;'.
Below are the text strings that are being generated by the code:
'CITIZEN CONCERN','CORRESPONDENCE LOG','INTEL','LAWSUIT'
'CITIZEN CONCERN','CORRESPONDENCE LOG','INTEL','LAWSUIT','EMAIL'
'CITIZEN CONCERN','CORRESPONDENCE LOG','INTEL','LAWSUIT','EMAIL','VIDEO'
'CITIZEN CONCERN','CORRESPONDENCE LOG','INTEL','LAWSUIT','EMAIL','VIDEO','WINDOW'
As you can see it appears the 3rd element in the string 'LAWSUIT' has the closing quotation. I have also copied and pasted the above string results directly into a query on the SQL server and get the expected results.
Can anyone see a problem with this code or explain why I can not get it to work.