2016-07-26 5 views
0

私は、gridview経由でCRMデータベースを更新できるようにアプリケーションを開発しようとしています。C#のCRMルックアップフィールドを更新します

ルックアップフィールドを更新しようとするまで、私が持っていたことはすべて動作していました。それは私にエラーを与える更新にルックアップフィールドを追加しようとすると、今

_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); 

:以下

は、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); 
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 

答えて

1

は、念のためにある、tog_techidだけtog_techidnameと呼ばれるか、ルックアップフィールドのですか?すべてのルックアップには関連する名前フィールドがあります。ルックアップ名+「名前」ですが、直接更新することはできません。 idをEntityReferenceで更新するだけで十分です。

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

で試してみてください私はちょうどそれを試してみましたが、それが同じエラーで失敗しました。私は100%は "機器"が正しいと確信していない。 EntityReference()のパラメータはどのようにすべきですか? – MMoore94

+0

また、 "tog_techidname"はデータベース内の列名です。私はデータベースの機器のビューを見て、それはequipmentidと名前が含まれています。それはequipmentidnameを含んでいません。 – MMoore94

+0

CRMエンティティのフィールドの名前は何ですか? EntityReferenceはエンティティのLogicalNameとGuidのペアである必要があります。 – Jordi

関連する問題