sql server - getting error with getint(0) in c# -


in code have error reading columns data base reader query. error in line :

dbcom.commandtext = system.string.format("insert cortex(idda,vlsd) values({0},'yes')",dbreader.getint16(0)); 

they saied no data exist in ligne or colomn, exist.

public static void main(string[] args)         {             using (odbcconnection dbconnection = new odbcconnection("dsn=savior"))             {                 dbconnection.open();                 odbccommand dbcommand = dbconnection.createcommand();                 dbcommand.commandtext = "select ida dchas";                 try                 {                     dbreader = dbcommand.executereader();                     int fcount = dbreader.fieldcount;                     if (fcount > 0)                     {                                                 {                              using (odbcconnection dbconnect = new odbcconnection("dsn=savior"))                             {                                 dbconnect.open();                                 odbccommand dbcom = dbconnect.createcommand();                                 dbcom.commandtext = system.string.format("insert cortex(idda,vlsd) values({0},'yes')",dbreader.getint16(0));                                  try                                 {                                     dbcom.executenonquery();                                 }                                 catch (odbcexception ex)                                 {                                     console.writeline("executing query2 failed.");                                     console.writeline("the odbccommand returned following message");                                     console.writeline(ex.tostring());                                     return;                                 }                             }                          } while (dbreader.read());                     }                     else                     {                         console.writeline("query affected row(s)");                         return;                     }                 }                 catch (odbcexception ex)                 {                     console.writeline("executing query1 failed.");                     console.writeline("the odbccommand returned following message");                     console.writeline(ex.tostring());                     return;                 }             }         } 

you entering do..while loop without call dbreader.read before trying access dbreader data.

the best fix change loop to

while(dbreader.read()) {     .....  } 

this avoid enter loop if reader query doesn't return records


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -