first Create a web application.from Framwork 4.0.
In ASPX we can give one label, one textbox and one button
My example:
<p>
this is the trail to create a record in "new_cooldrink" entity at dynamic crm
2011.</p>
<p>
<asp:Label ID="Label1" runat="server" Text="name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="save" />
</p>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using System.Net;
using Microsoft.Xrm.Sdk;
using System.Runtime.Serialization;
using System.Data;
using System.Data.Entity;
namespace connectcrm2011
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//This URL needs to be updated to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("http://<servername>/<organization name>/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
//Instantiate the contact object and populate the attributes.
Entity contact = new Entity("contact");
//Entity new_cooldrink = new Entity("new_cooldrink");
contact["lastname"] = TextBox1.Text.ToString();//txtFirstName.Text.ToString();
//new_cooldrink["new_name"] = Application["oauth_access"].ToString();
//contact["lastname"] = txtLastName.Text.ToString();
//contact["emailaddress1"] = txtEmailAddress.Text.ToString();
//contact["telephone1"] = txtPhoneNumber.Text.ToString();
Guid newContactId = service.Create(contact);
//for account entity
//Guid newaccountId = service.Create(account);
//Guid newnew_cooldrinkid = service.Create(new_cooldrink);
//This code will clear the textboxes after the contact is created.
TextBox1.Text = "";
}
}
}
}
Note : must add the reference
1. System.Runtime.Serialization
2.System.Data.Entity
in reference area.
may be cause for error:
<compilation debug="true" targetFramework="4.0">
In ASPX we can give one label, one textbox and one button
My example:
<p>
this is the trail to create a record in "new_cooldrink" entity at dynamic crm
2011.</p>
<p>
<asp:Label ID="Label1" runat="server" Text="name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="save" />
</p>
code in c#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using System.Net;
using Microsoft.Xrm.Sdk;
using System.Runtime.Serialization;
using System.Data;
using System.Data.Entity;
namespace connectcrm2011
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//This URL needs to be updated to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("http://<servername>/<organization name>/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{
IOrganizationService service = (IOrganizationService)serviceProxy;
//Instantiate the contact object and populate the attributes.
Entity contact = new Entity("contact");
//Entity new_cooldrink = new Entity("new_cooldrink");
contact["lastname"] = TextBox1.Text.ToString();//txtFirstName.Text.ToString();
//new_cooldrink["new_name"] = Application["oauth_access"].ToString();
//contact["lastname"] = txtLastName.Text.ToString();
//contact["emailaddress1"] = txtEmailAddress.Text.ToString();
//contact["telephone1"] = txtPhoneNumber.Text.ToString();
Guid newContactId = service.Create(contact);
//for account entity
//Guid newaccountId = service.Create(account);
//Guid newnew_cooldrinkid = service.Create(new_cooldrink);
//This code will clear the textboxes after the contact is created.
TextBox1.Text = "";
}
}
}
}
1. System.Runtime.Serialization
2.System.Data.Entity
in reference area.
may be cause for error:
No comments:
Post a Comment