c# - loop returns despite break -


i running loop cycle through entries in database. every time loop runs compare user's answer value in database. table rows named answer2, answer3...etc concatenate string: ("answer" + (i)) , use string database.queryvalue(string) put value database variable. (in case variable caltansx)

eventually loop returns null value. want loop terminate before runs again. try load queried value object , comparing dbnull.value try exit loop break; still comparing 2 strings. i.e. uans.tolower() == cans.tolower(). code returns error since cannot convert null value string. exit these loops once query loads null value (and before script can attempt convert string).

i have tried using break , return end string, still same problem.

if (!request.querystring["uanswer"].isempty()) { uans = request.querystring["uanswer"];  if (uans.tolower() == cans.tolower())         {             anbool = true;         }         else                //should cycle through answers in alternativeanswers table         {             (var = 0; < 30; i++)                   {                                   if (uans.tolower() == caltansx.tolower())                                     {                                         anbool = true;                                     }                                     else                                     {                                         altansxcom = altansxcom+1;                                         string x = altansxcom.tostring();                                         altcommandtemp = string.concat(altans1com, x, altans2com, sqterm);                                         caltansx = db.queryvalue(altcommandtemp);                                         objcaa = db.query(altcommandtemp);                                         if (objcaa == dbnull.value)   {break;}                                         if (caltansx == null) {break;}                                     }                      }             if (anbool != true)                 {             anbool = false;                 }         } 

you " program still crashes since still compares null value string in top part of script." assume means because caltansx null , trying call caltansx.tolower()?

in code break if objcaa null. think need check if caltansx null.

if (uans.tolower() == caltansx.tolower()) {     anbool = true; } else  // reloads query before subsequent comparison {     ...     caltansx = db.queryvalue(altcommandtemp);     objcaa = db.query(altcommandtemp);     if (objcaa == dbnull.value)   {break;}     if (caltansx == null)   {break;} } 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -