public static DataTable ToDataTable(this DataGridView dataGridView, string tableName = null)
{
DataGridView dgv = dataGridView;
DataTable table = new DataTable(tableName); for (int iCol = ; iCol < dgv.Columns.Count; iCol++)
{
table.Columns.Add(dgv.Columns[iCol].Name);
} foreach (DataGridViewRow row in dgv.Rows)
{
DataRow datarw = table.NewRow();
for (int iCol = ; iCol < dgv.Columns.Count; iCol++)
{
datarw[iCol] = row.Cells[iCol].Value;
}
table.Rows.Add(datarw);
} return table;
}
05-11 13:17