I am doing Randomly selecting the questions , when i select from the chapters from the checkboxliat only from that chapters all the questions should display in C# windows forms
using access .
I am getting error like this
Syntax error (missing operator) in query expression 'where chaptername='Electromagnetic Induction''.
and my query is
" SELECT top 5 questions FROM [tblques] ORDER BY Rnd(quescode) where
chaptername=' " + checkedListBox1.SelectedItem + " ' ", con);
Loading

VulpesRank #55 · 29.2K reputationPosted Jul 17, 2012, 1:31 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 16, 2012, 12:07 PM EDT
For example:
Electomagnetic Induction's Principles
If so, then Access will read the embedded quote as the end of the string and the remaining characters will generate an error.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 16, 2012, 7:26 PM EDT
I agree with Vulpes.
In this case you can use parameterize query.
Please refer
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter%28v=vs.80%29.aspx
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter.aspx\
hope this will help you.
rashmi kc89 reputationPosted Jul 16, 2012, 10:08 PM EDT
can i use my query like this ...
" SELECT top 5 questions FROM [tblques] ORDER BY Rnd(quescode) where
chaptername=' " + checkedListBox1.SelectedItem + " ' ", con);
Syntax error (missing operator) in query expression
ths s the error
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 16, 2012, 11:15 PM EDT
Example :If our text is "Electomagnetic Induction's Principles"
so our final query (which run on SQL server) become
SELECT top 5 questions FROM [tblques] ORDER BY Rnd(quescode) where
chaptername='Electomagnetic Induction's Principles'
right? so now our query is braek from 's and sql server consider only one part (Electomagnetic Induction) so error is comes.
hope you understand now.