string - C# - store data from database in 2 column list -


    public static list<string>[] columntolist2(string table, list<string>[]data, npgsqlconnection ncon)     {         using (ncon)         {             npgsqldataadapter da = new npgsqldataadapter("select id, name " + table + "", ncon);             dataset ds = new dataset();             da.fill(ds, "" + table + "");             foreach (datarow row in ds.tables["" + table + ""].rows)             {                 //testing area                 //console.writeline(row["id"].tostring());                 //console.writeline(row["name"].tostring());                  data[0].add(row[0].tostring());                 data[1].add(row[1].tostring());                                 }         }         return data;     } 

hello again! time want ask advice searching id value, storing both columns in list array. when test input in console there want, when try see after input in list, there isnt resut wanted (id name - list) here goes definition of variables:

        list<string>[] data_array = new list<string>[];         datu_array[0]=new list<string>();         datu_array[1]=new list<string>(); 

when try see output through console, there , error - havent defined array size

i hope u can me solve problem, in advance.

i assume want list<string[]> instead of list<string>[]. 1 list , every row string[] columns strings.

you use linq:

list<string[]> data = ds.tables[0].asenumerable()  .select(row => row.itemarray     .select(col => col.tostring())     .toarray())  .tolist(); 

but why don't stay datatable has advantages on list, example columns can either access via ordinal index or via name.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -