我有一个查询 CRM 2011 然后将结果绑定到 DropDownList 的方法,这是我的代码:
public void CheckRsmPopulateAccounts()
{
string rsmFirstName = _currentUser.FirstName;
string rsmLastName = _currentUser.LastName;
ddlCustomer.DataSource = (from r in gServiceContext.CreateQuery("opportunity")
join c in gServiceContext.CreateQuery("account") on ((EntityReference)r["accountid"]).Id equals c["accountid"]
join u in gServiceContext.CreateQuery("systemuser") on ((EntityReference)r["ownerid"]).Id equals u["systemuserid"]
where u["firstname"].Equals(rsmFirstName) && u["lastname"].Equals(rsmLastName)
select new
{
AccountId = !r.Contains("accountid") ? string.Empty : r["accountid"],
Account = !c.Contains("name") ? string.Empty : r["name"]
});
ddlCustomer.DataValueField = "AccountId";
ddlCustomer.DataTextField = "Account";
ddlCustomer.DataBind();
}
但由于某种原因,它一直给我一个Exception has been thrown by the target of an invocation.
错误,它看起来像DataBind
命令。我似乎无法弄清楚这个问题,这个错误似乎很笼统。知道是什么原因造成的吗?
谢谢!