您好我尝试使用CRM SDK从CRM获取address1_latitude和address1_longitude这里是mu代码
var querybyattribute11 = new QueryByAttribute("account");
querybyattribute11.ColumnSet = new ColumnSet("name", "address1_city", "statuscode", "address1_postalcode", "address1_latitude", "address1_longitude");
querybyattribute11.Attributes.AddRange("name");
querybyattribute11.Values.AddRange("ASSOCIATED COMBUSTION INC");
EntityCollection entities = service.RetrieveMultiple(querybyattribute11);
foreach (Entity item in entities.Entities)
{
// Console.WriteLine("Name: {0}. Id: {1}", role.Name, role.Id);
list += item.Attributes["name"].ToString() + " " + item.Attributes["address1_longitude"] .ToString() + "\n";
}
但我不是在考虑item.Attributes["address1_longitude"]
错误信息是
'The given key was not present in the dictionary.'
答案 0 :(得分:1)
可能是因为它是空的。
尝试以下两个选项之一:
item["address1_longitude"] (shouldn't raise exception, it would return null if blank, otherwise the address longitude)
检查列是否存在:
item.Attributes.ContainsKey("address1_longitude")