Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone!

I am in the process of making ongoing modifications to my program. I've stumbled across a query that the compiler can't parse and I'm not sure why.

Here is the query:
SqlCeCommand cc_waveform_fullname_comms = new SqlCeCommand("SELECT file_name FROM waveform_files WHERE file_name LIKE % (' " + cc_list_element + " ')", conn);
cc_waveform_fullname_comms.CommandType = CommandType.Text;
SqlCeDataReader cc_waveform_fullname_comms_dr = cc_waveform_fullname_comms.ExecuteReader();

The compiler is balking at this statement:
SqlCeDataReader cc_waveform_fullname_comms_dr = cc_waveform_fullname_comms.ExecuteReader();

For this reason:
{"There was an error parsing the query. [ Token line number = 1,Token line offset = 59,Token in error = % ]"}

I am using C# with Visual Studio 2012.

My guess is is that the compiler doesn't like the % for LIKE comparisons. Am I on the right track or is there more to the story that I'm not seeing?
Posted
Comments
Sergey Alexandrovich Kryukov 18-Oct-12 19:28pm    
What, do you thing your compiler parses the query?!
Sorry, my 1.
--SA

1 solution

The % should appear within the single quote, I would also change your query to use parameters instead of the inline concatenation you use. The way you have it, sql injection is a huge risk.
SQL
... SELECT file_name FROM waveform_files WHERE file_name LIKE '%" + cc_list_element + "'"
 
Share this answer
 
v2
Comments
joshrduncan2012 18-Oct-12 17:20pm    
Thanks Marcus! That did the trick! Very much appreciated!
fjdiewornncalwe 18-Oct-12 17:22pm    
Cheers.
Maciej Los 18-Oct-12 17:22pm    
Good work, +5!
fjdiewornncalwe 18-Oct-12 17:23pm    
Thanks, Maciej
Sergey Alexandrovich Kryukov 18-Oct-12 19:28pm    
5ed. I just want to bring to your attention that OP probably think that a compiler parses the query, which is very wrong.
--SA

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