.net - How to populate List using DataTable and For Each Loop? -


i'm trying populate list using datatable, have each loop checks every row , adds item list. code isn't working, keep getting error..

system.nullreferenceexception: {"object reference not set instance of object."}

-data: {system.collections.listdictionaryinternal}

-helplink: nothing -inner exception: nothing

-targetsite: {system.collections.generic.list`1[system.string] getlistofusers()}

this code...

function getlistofusers() list(of string)      'dim integer = 0     dim lusernames list(of string) = nothing      dim dt datatable = getdatatable(db_config, "select * tblusers")      if dt.rows.count > 0          try              each drowitem datarow in dt.rows                  'i = + 1                  'if isdbnull(dt.rows(0)("fldusername").tostring) = false                 '    lusernames.add(dt.rows(0)("fldusername").tostring)                 'end if                  if drowitem.item("fldusername").tostring <> ""                     lusernames.add(drowitem.item("fldusername").tostring)                 end if              next drowitem          catch ex exception             msgbox(ex.tostring)         end try      end if      return lusernames  end function 

currently lusernames has not been initialized. need this:

dim lusernames new list(of string) 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -