/// <summary>
/// datagridview to a datatable
/// geovindu 涂聚文
/// </summary>
/// <param name="dataGridView"></param>
/// <returns></returns>
private DataSet DataGridViewToDatSet(DataGridView dataGridView)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.TableName = "StaffStateList";
foreach (DataGridViewColumn col in dataGridView.Columns)
{
dt.Columns.Add(col.DataPropertyName, col.ValueType);
}
foreach (DataGridViewRow gridRow in dataGridView.Rows)
{
if (gridRow.IsNewRow)
continue;
DataRow dtRow = dt.NewRow();
for (int i1 = 0; i1 < dataGridView.Columns.Count-1; i1++)
dtRow[i1] = (gridRow.Cells[i1].Value == null ? DBNull.Value : gridRow.Cells[i1].Value);
dt.Rows.Add(dtRow);
}
ds.Tables.Add(dt);
//System.Diagnostics.Debugger.Break();
return ds;
}
csharp datagridview to a datatable,a dataset
最新推荐文章于 2024-04-08 07:08:18 发布