.net - C# mysql returning list of rows -


i return arraylist of values mysql database. have tried couple of solutions not elegant need. problem: have table in database can change structure (alter table). need way detect current table structure , put data in array list right types (no casting object) there solutions problem ? dont want logic written bellow inside while.

idbcommand sql = dblink.createcommand (); sql.commandtext = "select * table cond";  idatareader reader = null;  try  {     reader = sql.executereader (); }  catch (exception er)  {     log.error ("error executing query"); }  while(reader.read())  {     //dont want     value = (string)reader["item"];     //logic implement }   reader.close (); reader = null; sql.dispose (); sql = null; 

given arraylist going store object anyway, can use:

list.add(reader["item"]); 

that puts onus on whatever's going fetch list cast before can useful though. think whatever code is going consume these results, , how you're expecting handle them.

(i agree arran's comment though - should use using statements. also, never want set variables null after you're done them, shouldn't catch exception, , shouldn't try use reader after exception has been thrown - you'll end nullreferenceexception.)


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -