繁体   English   中英

从C#更新CRM查找字段

[英]Update CRM Lookup Field from C#

我正在尝试开发一个应用程序,以允许通过gridview更新我们的CRM数据库。

在尝试更新查找字段之前,我一直在进行所有操作。

以下是有效的C#代码:

_service = GlobalFunctions.GetServiceAccount();
GlobalFunctions.User u = (GlobalFunctions.User)Session["UserInfo"];

Entity aspiration = new Entity("tog_aspiration");
aspiration.Id = new Guid(inputGridView.DataKeys[e.RowIndex].Value.ToString());
aspiration["tog_nofollrl"] = Int32.Parse(tog_nofollrl);
_service.Update(aspiration);

现在,当尝试将查找字段添加到更新时,它给了我一个错误。

_service = GlobalFunctions.GetServiceAccount();
GlobalFunctions.User u = (GlobalFunctions.User)Session["UserInfo"];

Entity aspiration = new Entity("tog_aspiration");
aspiration.Id = new Guid(inputGridView.DataKeys[e.RowIndex].Value.ToString());
aspiration["tog_nofollrl"] = Int32.Parse(tog_nofollrl);
aspiration["tog_techidname"] = new EntityReference("equipment", new Guid(ddlVet.SelectedValue));
_service.Update(aspiration);

这是错误

Incorrect attribute value type System.String 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Incorrect attribute value type System.String

只是为了确保,查找字段称为tog_techidname还是仅仅是tog_techid? 每个查找都有一个关联的名称字段,即查找名称+“名称”,但是您不能直接更新它。 只需使用EntityReference更新ID就足够了。

试试看

aspiration["tog_techid"] = new EntityReference("equipment", new Guid(ddlVet.SelectedValue));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM