Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can somebody please tell me if something is wrong with this line it gives this error
C#
Syntax error: Missing operand after 'name' operator."

DataRow[] rows = table.Select(columnY +"='"+ columnYValue +"'");

The table contains the supposed rows.
Posted
Comments
Member 12081613 19-Nov-15 15:58pm    
My coloumn name here has a space between. if that could be the issue then How to fix it?
BillWoodruff 19-Nov-15 17:21pm    
show more of your code ... show the part where the "parameters" are defined.
BillWoodruff 19-Nov-15 21:56pm    
Without detailed information from you, we can only guess what you are doing. So, please, provide that information.

Does the value of
C#
columnY +"='"+ columnYValue +"'"
contain a valid filter?

The space in the column name should be fixable by enclosing the column name in square brackets []
C#
string.Format("[{0}]='{1}'", columnY, columnYValue)
See: https://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(v=vs.100).aspx[^]

[Edit: MTH]
This is assuming that table is a System.Data.DataTable
 
Share this answer
 
v2
Comments
Member 12081613 19-Nov-15 16:55pm    
Yes, it is but I dont get where to use the string.format line
Matt T Heffron 19-Nov-15 17:25pm    
exactly instead of the
columnY +"='"+ columnYValue +"'"
Matt T Heffron 19-Nov-15 20:43pm    
Did it work?
BillWoodruff 19-Nov-15 21:55pm    
With this question, I don't think we have enough information about what the OP is doing to do anything but ... guess.
Member 12081613 20-Nov-15 2:11am    
OMG string.Format("[{0}]='{1}'", columnY, columnYValue) worked. Thanks a million Matt
This is not LINQ (as you state in the tags) what you show here. LINQ would return an IEnumerable<T> and the Select method requires a delegate, usually given as a lambda expression.
What exactly do you want to select? All elements of a table? Do you want to apply any filter (e.g. a Where call)?
Regards
Andi
 
Share this answer
 
Comments
Member 12081613 19-Nov-15 16:46pm    
I want to select rows where ColumnY=columnYValue.
Member 12081613 19-Nov-15 16:51pm    
Both are strings
Member 12081613 19-Nov-15 16:58pm    
Please, if this isnt right show me how to?

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