Filling Datatable with DataGridView data in VB/C# .NET -
how can fill datatable datagridview data (vb/c# .net)?
assuming winform
below code can of help
//dgv name of data grid view. datatable dt = new datatable(); datacolumn[] dcs = new datacolumn[]{}; foreach (datagridviewcolumn c in dgv.columns) { datacolumn dc = new datacolumn(); dc.columnname = c.name; dc.datatype = c.valuetype; dt.columns.add(dc); } foreach (datagridviewrow r in dgv.rows) { datarow drow = dt.newrow(); foreach (datagridviewcell cell in r.cells) { drow[cell.owningcolumn.name] = cell.value; } dt.rows.add(drow); }
Comments
Post a Comment