c# - How to dynamically fill a row in a DataTable? -


datatable exporttable = new datatable();  exporttable.columns.add("place", typeof(string)); exporttable.columns.add("day", typeof(string));  foreach (var time in timelist) {     exporttable.columns.add(time, typeof(string));  }  exporttable.rows.add("new york", 1/1/2015, ?, ?, ?, ...); 

how can dynamically fill row in datatable?

here's 1 way:

    datatable itemtable = new datatable("mytable");     itemtable.columns.add("id"      , typeof(int   ));     itemtable.columns.add("parentid", typeof(int   ));     itemtable.columns.add("name"    , typeof(string));       // add test data     itemtable.rows.add(new object[] { 0,-1, "bill gates"    });     itemtable.rows.add(new object[] { 1, 0, "steve ballmer" });     itemtable.rows.add(new object[] { 3, 1, "mary smith"    });     itemtable.rows.add(new object[] { 2, 0, "paul allen"    });     itemtable.rows.add(new object[] { 4, 2, "ahmed jones"   });     itemtable.rows.add(new object[] { 5, 2, "wing lee"      } ); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -