asp.net - How can I access the rows in a certain column of a DataTable? -


i need populate rows in specific columns of datatable. have following setup:

dim dt datatable = new datatable() dim da sqldataadapter = new sqldataadapter() dt.columns.add("column 0") dt.columns.add("column 1") try         sqlconn.conopen()         da.selectcommand = sqlcmd_loccodes         da.fill(dt)         sqlconn.conclose()      catch ex exception         sqlconn.conclose()     end try 

the sqldataadapter filling table data database. need able store data database specific columns in datatable. i'm trying (i'm populating barchart data, can ignore part):

for integer = 0 dt.rows().count - 1         chart.series("series1").points.addy(dt.rows(i)("column 0").tostring())         chart.series("series1").points(i).axislabel = dt.rows(i)("column 0").tostring()         next 

i know i'm doing simple task incorrectly. going accessing particular rows incorrectly? appreciated.

you can iterate rows in datatable this:

for each dr datarow in dt.rows     chart.series("series1").points.addy(dr("column 0").tostring())     chart.series("series1").points(i).axislabel = dr("column 0").tostring()) next 

however, better off removing this:

dt.columns.add("column 0") dt.columns.add("column 1") 

just let dataadapter name columns per column names specified in query.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -