日期:2014-05-18  浏览次数:20724 次

dataview填充datatable问题
dataview.RowFilter后,如何把dataview填充到一个新的datatable中?

------解决方案--------------------
Dim dtb as datatable=dataview.toTable
------解决方案--------------------
public static DataTable CreateTable(DataView obDataView)
{
if( null == obDataView)
{
throw new ArgumentNullException("DataView","Invalid DataView object specified");
}
DataTable obNewDt = obDataView.Table.Clone();
int idx = 0;
string[] strColNames = new string[obNewDt.Columns.Count];
foreach(DataColumn col in obNewDt.Columns)
{
strColNames[idx++] = col.ColumnName;
}
IEnumerator viewEnumerator = obDataView.GetEnumerator();
while(viewEnumerator.MoveNext())
{
DataRowView drv = (DataRowView)viewEnumerator.Current;
DataRow dr = obNewDt.NewRow();
try
{
foreach(string strName in strColNames)
{
dr[strName] = drv[strName];
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
obNewDt.Rows.Add(dr);
}
return obNewDt;
}
------解决方案--------------------
可以
------解决方案--------------------
不行,dv.ToTable();方法是新DataTable中的行状态都是Added