Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
ERROR:The items following the IN keyword must be separated by commas and be enclosed in parentheses.

my code is

What I have tried:

DataRow[] rows = dt.Select("CompanyID not in oCompanyBO.SelectedSupplierIDs");
Posted
Updated 1-Jun-16 6:14am
Comments
Karthik_Mahalingam 1-Jun-16 7:38am    
what is oCompanyBO.SelectedSupplierIDs
shukla parth 1-Jun-16 8:44am    
i fill the data in ds
Karthik_Mahalingam 1-Jun-16 8:48am    
SelectedSupplierIDs is a list or array or what is it?
Herman<T>.Instance 1-Jun-16 7:48am    
Example here!
ZurdoDev 1-Jun-16 7:54am    
I think the error actually explains the problem pretty well, doesn't it? You need to do NOT IN ('one, 'two', 'etc')

1 solution

Cannot be sure with so little information, but I think that your problem is that you embed a variable name in a string, when you want to use the value of the variable.

C#
DataRow[] rows = dt.Select("CompanyID not in oCompanyBO.SelectedSupplierIDs");

should be
C#
DataRow[] rows = dt.Select(string.Format("CompanyID not in ({0})", oCompanyBO.SelectedSupplierIDs));

if oCompanyBO.SelectedSupplierIDs is a comma separated list.

However, if oCompanyBO.SelectedSupplierIDs is an array of SelectedSupplierID (int) then you need to first create a comma separated string
C#
string idList = string.Join(",", oCompanyBO.SelectedSupplierIDs);
DataRow[] rows = dt.Select(string.Format("CompanyID not in ({0})", idList));
 
Share this answer
 
v3
Comments
Richard Deeming 1-Jun-16 12:59pm    
For your last example, string.Join would be better than concatenating strings in a loop:

string idList = string.Join(",", oCompanyBO.SelectedSupplierIDs);
George Jonsson 1-Jun-16 13:17pm    
True, I was a bit lazy in my old ways there.
George Jonsson 1-Jun-16 13:21pm    
Changed it to your more elegant solution.
I always forget that Join function.

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