我收到错误
“已添加具有相同键的项目”
随机生产。如果我在本地执行以下代码我没有得到问题。需要解决此问题的建议。
//check for whether Midas.DAB is Enabled in the App.Config File
if (ProcessMidasDab)
{
var dvFilteredMidasDabDetails = new DataView(dtMidasDabandSurgDetails) {
RowFilter = "not (LastReceivedOnForDAB is null)" };
dtCmMidasDabAlerts.Columns.Add("ClientID");
dtCmMidasDabAlerts.Columns.Add("LastFileReceivedDate");
dtCmMidasDabAlerts.Columns.Add("SendingSystem");
//Get the Cut-off time for Midas.DAB from the App.config.
var timeStamp = ConfigurationManager.AppSettings["TimeLapseforMidasDABinhrs"];
//Logic to check the Feed for Midas.DAB
foreach (DataRowView dv in dvFilteredMidasDabDetails)
{
midasDabClientList.Add(Convert.ToInt32(dv["ClientID"]));
var timeDifference =
(DateTime.Now - Convert.ToDateTime(dv["LastReceivedOnForDAB"])).TotalHours;
if (timeDifference > Convert.ToDouble(timeStamp))
{
var drNewRow = dtCmMidasDabAlerts.NewRow();
drNewRow["ClientID"] = dv["ClientID"];
drNewRow["LastFileReceivedDate"] = dv["LastReceivedOnForDAB"];
drNewRow["SendingSystem"] = "Midas.DAB";
dtCmMidasDabAlerts.Rows.Add(drNewRow);
}
}
dabclients = midasDabClientList;
}
答案 0 :(得分:0)
你有两次分配这个
drNewRow["Clientid"] = 12;
drNewRow["ClientID"] = dv["ClientID"];
请删除此
drNewRow["Clientid"] = 12;
并且您还有两次分配此
dtCmMidasDabAlerts.Columns.Add("ClientID");