2009-04-20 26 views

cevap

36
dt = DataView.ToTable() 

TD

dt = DataView.Table.Copy()

,

TD

dt = DataView.Table.Clone();

+1

sayesinde google oldukça kötü bir şekilde beni başarısız oldu. Umarım bu sayfa yüksek sıralanır. – Ravedave

+1

Teşekkürler Jose ... Çalıştı ... –

+8

Not: 'DataView.ToTable()' sadece DataView değerlerini kopyalayacaktır. DataView.Table.Copy() 'DataView'ın filtrelenmiş verilerini değil, kaynak DataTable'ı kopyalayacaktır. DataView.Table.Clone() 'sadece DataTable kaynağının yapısını kopyalayacaktır. – Homer

3

Durumum için yanıt çalışmıyor çünkü ifadeleri olan sütunlarım var. DataView.ToTable() sadece değerleri değil, ifadeleri kopyalayacaktır.

Öncelikle bu çalıştı:

//clone the source table 
DataTable filtered = dt.Clone(); 

//fill the clone with the filtered rows 
foreach (DataRowView drv in dt.DefaultView) 
{ 
    filtered.Rows.Add(drv.Row.ItemArray); 
} 
dt = filtered; 

ama bu çözüm bile sadece 1000 satırlar için çok yavaştı.

benim için çalıştı çözüm:

//create a DataTable from the filtered DataView 
DataTable filtered = dt.DefaultView.ToTable(); 

//loop through the columns of the source table and copy the expression to the new table 
foreach (DataColumn dc in dt.Columns) 
{ 
    if (dc.Expression != "") 
    { 
     filtered.Columns[dc.ColumnName].Expression = dc.Expression; 
    } 
} 
dt = filtered; 
İlgili konular