[英]How to delete account in dynamics crm using c#?
public void DeleteAccount()
{
IOrganizationService service;
Entity account = new Entity("account");
Guid accountId = account.Id;
**//accountId empty :(**
service.Delete("account", accountId);
}
如何使用C#刪除Dynamics CRM中的帳戶? (我使用gridview加載了列表帳戶,但沒有帳戶ID)
您需要使用“檢索多個”要求來獲取帳戶ID,或者您需要對GUID進行硬編碼以刪除記錄。
上面的代碼將始終返回空的GUID,因為您正在此處創建新對象。
下面的代碼將搜索名稱為test account
Account
實體,檢索並刪除它。 我假設您已經使用與CRM的連接字符串初始化了IOrganizationService
。
IOrganizationService service; //initialize this
QueryByAttribute query = new QueryByAttribute();
query.ColumnSet = new ColumnSet("name");
query.Attributes.AddRange("name");
query.Values.AddRange("test account");
Entity accountEntity = service.RetrieveMultiple(query).Entities.FirstOrDefault();
if (accountEntity != null)
{
Guid accountID = accountEntity.Id;
service.Delete("account", accountID);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.