Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a Where clause like
"copkshopno in ('5') and"

I want to append another filter in my where clause with same parameter like
"copkshopno in ('5,6,7,8') and"



As you see i have appended 6,7,8 how i can achieve this.

What I have tried:

string A = (ctrlParam as DNTextBox).ConnectedField + "in('"; //this one is used because i want to append text after this Text.
whereCondition += whereCondition.IndexOf(A) + string.Join(",", selectItems) + ") and ";
Posted
Updated 23-Aug-16 22:21pm

use String.Format[^], which will simplify the string concatenation.

C#
int[] items = new int[] { 1,2,3,4};
      string whereIn = string.Format(" in('{0}') and",string.Join(",",items));
      whereCondition += whereIn;


Formatting the sql Query string is vulnerable to SQL Injection[^] attacks
always use Parameterized queries to prevent SQL Injection Attacks in SQL Server[^]
 
Share this answer
 
v2
Comments
Maciej Los 24-Aug-16 4:09am    
Karthik, i'd NOT recommend to use string concatenation with SQL. OP needs to pass whereIn variable as a parameter into command, instead of concatenating it with whereCondition into single string (command).
Karthik_Mahalingam 24-Aug-16 4:15am    
Yes Maciej
updated the solution.
I have just answered to the context.
Maciej Los 24-Aug-16 4:21am    
5ed!
Please, see my answer ;)
Karthik_Mahalingam 24-Aug-16 4:27am    
Thank you Maciej
The Praveen Singh 24-Aug-16 5:18am    
@Karthik Actually you don't undersatnd what i exactly want to ask:-
whereCondition += (ctrlParam as DNTextBox).ConnectedField + " in ('" + string.Join("','", (ctrlParam as DNTextBox).Text.Replace(",", "','")) + "') and ";
Above syntax returns "copkshopno in ('5') and"
Again through loop next param comes Shopgroup in which multiple shop were found i want to append that in my wherecondition in query for coshopno.
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 24-Aug-16 4:29am    
5! for the highlight :)
bookmarked this answer, will refer this for future questions related to sql injection :)
Maciej Los 24-Aug-16 5:28am    
Thank you, Karthik.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900