I am trying to sync data from an SQL Server to Dynamics CRM.
I had created a solution/project in C#. Where syncing an account entity of CRM, all the details like name, account number, ship date, phone number all this kind of detail are successfully syncing because form SQL, the data type is nvarchar
or int
and in CRM it is a single line of text.
But while I am doing the same sync from nvarchar
to a lookup field of CRM it is not working and the exception occurs.
Here, the account is the name of the entity in CRM and SalesContact is name of the field from SQL and data type is nvarchar
and ppg_salescontact is the name of the field in CRM and data type is lookup.
Entity enAccount = new Entity("account");
if (!String.IsNullOrEmpty(drRowAccount["SalesContact"] + "")) { enAccount["ppg_salescontact"] =
SecurityElement.Escape(drRowAccount["SalesContact"].ToString().Trim()); }
Exception :" Message : Error converting attribute value to Property: Attribute [ppg_salescontact], Attribute type [lookup] of Entity [account] with value of type [System.String]: [System.InvalidCastException: Unable to cast object of type 'System.String' to type 'Microsoft.Xrm.Sdk.EntityReference'. "
Please suggest me what can I do for this.