在c#中将dataRowview转换为dataTable
Convert dataRowview to dataTable in c#
我正在尝试将 dataRowview 转换为数据表:
private void Cell_Edit_End(object sender, DataGridCellEditEndingEventArgs e)
{
DataRowView rowView = e.Row.Item as DataRowView;
rowBeingEdited = rowView;
}
DataTable dt = new DataTable();
foreach (DataRow row in rowBeingEdited.Row.GetChildRows) {
dt.ImportRow(row);
}
谁能帮我解决
您可以使用 DataRow.Table.Clone()
获得具有相同列的空 table:
DataRow[] childRows = rowBeingEdited.Row.GetChildRows("RelationName");
if (childRows.Length > 0)
{
DataTable tblChildren = childRows[0].Table.Clone();
foreach (DataRow row in childRows)
tblChildren.ImportRow(row);
}
我们可以直接将dataRowview转换成Datatable为:
DataTable dt = rowBeingEdited.DataView.ToTable();
如果有过滤器,这就是正确答案
datagridview.DataSource.current.DataView.ToTable()
我尝试了所有其他解决方案,但效果不佳或需要很长时间
我正在尝试将 dataRowview 转换为数据表:
private void Cell_Edit_End(object sender, DataGridCellEditEndingEventArgs e)
{
DataRowView rowView = e.Row.Item as DataRowView;
rowBeingEdited = rowView;
}
DataTable dt = new DataTable();
foreach (DataRow row in rowBeingEdited.Row.GetChildRows) {
dt.ImportRow(row);
}
谁能帮我解决
您可以使用 DataRow.Table.Clone()
获得具有相同列的空 table:
DataRow[] childRows = rowBeingEdited.Row.GetChildRows("RelationName");
if (childRows.Length > 0)
{
DataTable tblChildren = childRows[0].Table.Clone();
foreach (DataRow row in childRows)
tblChildren.ImportRow(row);
}
我们可以直接将dataRowview转换成Datatable为:
DataTable dt = rowBeingEdited.DataView.ToTable();
如果有过滤器,这就是正确答案
datagridview.DataSource.current.DataView.ToTable()
我尝试了所有其他解决方案,但效果不佳或需要很长时间