C# datatable的Winforms代码-what';WPF的等价物是什么?
我在Winforms应用程序中有以下代码,可以正常工作:C# datatable的Winforms代码-what';WPF的等价物是什么?,c#,.net,wpf,winforms,C#,.net,Wpf,Winforms,我在Winforms应用程序中有以下代码,可以正常工作: private void btnFetchCollections_Click(object sender, EventArgs e) { try { var scDal = new SiteCollectionDal(); var dt = new DataTable(); List<SiteCollectionEntity> siteCollections =
private void btnFetchCollections_Click(object sender, EventArgs e)
{
try
{
var scDal = new SiteCollectionDal();
var dt = new DataTable();
List<SiteCollectionEntity> siteCollections = scDal.FetchSiteCollections();
dt.Columns.Add(new DataColumn("Site Name", typeof(string)));
foreach (SiteCollectionEntity siteCollectionEntity in siteCollections)
{
DataRow row = dt.NewRow();
row["Site Name"] = siteCollectionEntity.Url;
dt.Rows.Add(row);
dt.AcceptChanges();
}
dataSiteCollections.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
即:
无法将源类型“System.Data.DataTable”转换为目标类型
“System.Collections.IEnumerable”
试试这个:
dataSiteCollections.ItemsSource = dt.AsDataView();
尝试插入
.ToList()代码>如下:dataSiteCollections.ItemsSource=dt.ToList()代码>@Tico刚刚给出错误“无法解析符号”ToList“可能的重复项”
dataSiteCollections.ItemsSource = dt;
dataSiteCollections.ItemsSource = dt.AsDataView();