c# - NullReferenceException was caught...? -


after running foreach loop. getting nullreferenceexception on second item, because query result null. have more item use on same query , result on richtextbox1. have can continue foreach loop if there null result.

foreach (string items in listbox4.items) {     using (oraclecommand crtcommand = new oraclecommand("select regexp_replace(dbms_metadata.get_ddl('table','" + items + "'),('" + txtsrcuserid.text + "...'),'', 1, 0, 'i') dual", conn1))                                {         richtextbox1.appendtext(environment.newline);         richtextbox1.appendtext(crtcommand.executescalar().tostring() + ";");         richtextbox1.appendtext(environment.newline);     }                                                       } 

this dangerous programming. should checking null. assuming loop bigger.. include continue , make bit more obvious you're doing readability. omit continue if don't need it.

var result = crtcommand.executescalar();  if (result != null) {     richtextbox1.appendtext(environment.newline);     richtextbox1.appendtext(result.tostring() + ";");     richtextbox1.appendtext(environment.newline); } else {     continue; }  // other code here. 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -