我正在尝试开发一个应用程序,允许通过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
答案 0 :(得分:1)
为了确保,查询字段是名为tog_techidname还是只是tog_techid?每个查找都有一个关联的名称字段,即查找名称+“名称”,但您无法直接更新它。仅使用EntityReference更新id就足够了。
尝试
aspiration["tog_techid"] = new EntityReference("equipment", new Guid(ddlVet.SelectedValue));