繁体   English   中英

如何使用C#删除Dynamics CRM中的帐户?

[英]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.

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