c# - How to add row with default values into System.Data.DataTable -


i have datatable , need add row default values , save database.

bonus: awesome auto increment key column.

how can achieve that?

static int = 1; private void createdefault() {     datacolumn column = null;     datatable table = new datatable();      column = new datacolumn();     var col1 = column;     col1.datatype = system.type.gettype("system.int32");     col1.defaultvalue = i;     col1.unique = false;     table.columns.add(column);     = + 1;      column = new datacolumn();     var col2 = column;     col2.datatype = system.type.gettype("system.string");     col2.defaultvalue = "your string";     table.columns.add(column);      datarow row = null;     row = table.newrow();      table.rows.add(row); } 

variable i auto increment key column. insert datatable database.


Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -