.Datagridview数据写入DataTable
System.Data.DataTable dt = new System.Data.DataTable();
dt.Clear();
foreach (DataGridViewColumn headerCell in dataGridView1.Columns)
{
dt.Columns.Add(headerCell.HeaderText);
}
foreach (DataGridViewRow item in dataGridView1.Rows)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < dt.Columns.Count; i++)
{
dr[i] = item.Cells[i].Value.ToString();
}
dt.Rows.Add(dr);
}
posted on 2012-08-17 11:39 the Jade Emperor 阅读(508) 评论(0) 编辑 收藏 举报