我想更新帐户的数据。如何访问和更新数据?
我可以使用此代码创建一个新帐户,但我也想更新:
private static CrmService ConnectToCrm()
{
CrmService service = new CrmService();
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "crm";
service.Url = "http://192.168.1.23:5555/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
return service;
}
protected void btnUpdateAccount_Click(object sender, EventArgs e)
{
try
{
CrmService MyService = ConnectToCrm();
DynamicEntity leadEntity = new DynamicEntity();
leadEntity.Name = EntityName.lead.ToString();
ArrayList arrProps = new ArrayList();
if (txtName.Text != string.Empty)
{
StringProperty firstname = new StringProperty();
firstname.Name = "firstname";
firstname.Value = txtName.Text;
arrProps.Add(firstname);
}
if (txtSurname.Text != string.Empty)
{
StringProperty lastname = new StringProperty();
lastname.Name = "lastname";
lastname.Value = txtSurname.Text;
arrProps.Add(lastname);
}
if (txtMail.Text != string.Empty)
{
StringProperty mail = new StringProperty();
mail.Name = "emailaddress1";
mail.Value = txtMail.Text;
arrProps.Add(mail);
}
if (txtState.Text != string.Empty)
{
StringProperty state = new StringProperty();
state.Name = "address1_stateorprovince";
state.Value = txtState.Text;
arrProps.Add(state);
}
leadEntity.Properties = (Property[])arrProps.ToArray(typeof(Property));
MyService.Create(leadEntity);
}
答案 0 :(得分:0)
更新工作与Creates非常相似。只需确保DynamicEntity具有要更新和替换的记录的GUID和实体名称
MyService.Create(leadEntity);
与
MyService.Update(LeadEntity);