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
VulpesPosted Jul 17, 2012, 5:31 AM
Jignesh TrivediPosted Jul 17, 2012, 3:15 AM
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.
rashmi kcPosted Jul 17, 2012, 2:08 AM
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 TrivediPosted Jul 16, 2012, 11:26 PM
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.
VulpesPosted Jul 16, 2012, 4:07 PM
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.