问题描述
我正在尝试查看 DataTable 的一行是否包含一个值,但它显示“System.Data.MissingPrimaryKeyException: 'Table 没有主键。'”我不知道为什么会有一个键需要在一行中找到一个值,并且需要一些关于如何正确浏览行以找到值的指导。 我用注释标记了引发异常的 if 语句。
DataTable OutputDV = new DataTable();
DataView ScrumTeams = ISBL.GetScrumTeams();
//this dataview returns this: [CountDate,ScrumTeam,DefectCount]
DataView alldefects = ISBL.Getdefects(dtstartdate,dtenddate);
//Adding the columns for the datview
DataColumn ScrumTeamName = new DataColumn("ScrumTeam",typeof(string));
ScrumTeamName.ReadOnly = true;
OutputDV.Columns.Add(ScrumTeamName);
//first create columns of all dates
foreach (DaTarow x in alldefects.ToTable().Rows)
{
//if there isnt a column by name of x then add one
if (!OutputDV.Columns.Contains(x["CountDate"].ToString()))
{
OutputDV.Columns.Add(x["CountDate"].ToString());
}
//CODE BELOW CAUSES EXCEPTION:
//System.Data.MissingPrimaryKeyException: 'Table doesn't have a primary key.'
if (!OutputDV.Rows.Contains(x["ScrumTeam"].ToString()) || OutputDV.Rows.Count == 0)
{
OutputDV.Rows.Add(x["ScrumTeam"].ToString());
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)