to retrieve data from crm 2011
we can use queryexpression.
first create condition expression.
then filter expression.
then query expression.
this code for login credential checking in crm 2011.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.ServiceModel.Description;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Xrm.Sdk.Query;
using System.Configuration;
using Sulekha.Order.CrmSdk;
using System.Linq.Expressions;
using Xrm;
using System.Data.SqlClient;
using System.Configuration;
namespace Sulekha.Order
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//SqlConnection con = new
Entity contacts = new Entity("contact");
string user = username.Text.ToString();
string pass = password.Text.ToString();
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
Uri OrganizationUri = new Uri("http://crmserver/databaseCRM/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
{
Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "firstname";
condition.Operator = ConditionOperator.Equal;
condition.Values.Add(user);
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "lastname";
condition1.Operator = ConditionOperator.Equal;
condition1.Values.Add(pass);
FilterExpression filter1 = new FilterExpression();
filter1.Conditions.Add(condition);
filter1.Conditions.Add(condition1);
QueryExpression query = new QueryExpression("contact");
query.ColumnSet.AddColumns("firstname", "lastname");
query.Criteria.AddFilter(filter1);
EntityCollection result1 = serviceProxy.RetrieveMultiple(query);
if (result1.Entities.Count > 0)
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('valid Username and Password')</script>");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('invalid Username and Password')</script>");
}
}
}
}
}
ref :
http://mileyja.blogspot.in/2011/07/convert-queryexpression-to-fetchxml.html
http://stackoverflow.com/questions/8669611/how-to-write-queryexpression-for-following-query
http://msdn.microsoft.com/en-us/library/gg334688.aspx
OptionSetValue osv = (OptionSetValue)entities.Attributes["statuscode"];
if (osv.Value == 1)
{
dr["Order Status"] = "New";
}
if (osv.Value == 2)
{
dr["Order Status"] = "Pending";
}
//dr["Order Status"] = osv.Value;
for optional set value
we can use queryexpression.
first create condition expression.
then filter expression.
then query expression.
this code for login credential checking in crm 2011.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.ServiceModel.Description;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Xrm.Sdk.Query;
using System.Configuration;
using Sulekha.Order.CrmSdk;
using System.Linq.Expressions;
using Xrm;
using System.Data.SqlClient;
using System.Configuration;
namespace Sulekha.Order
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//SqlConnection con = new
Entity contacts = new Entity("contact");
string user = username.Text.ToString();
string pass = password.Text.ToString();
ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
Uri OrganizationUri = new Uri("http://crmserver/databaseCRM/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
{
Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "firstname";
condition.Operator = ConditionOperator.Equal;
condition.Values.Add(user);
ConditionExpression condition1 = new ConditionExpression();
condition1.AttributeName = "lastname";
condition1.Operator = ConditionOperator.Equal;
condition1.Values.Add(pass);
FilterExpression filter1 = new FilterExpression();
filter1.Conditions.Add(condition);
filter1.Conditions.Add(condition1);
QueryExpression query = new QueryExpression("contact");
query.ColumnSet.AddColumns("firstname", "lastname");
query.Criteria.AddFilter(filter1);
EntityCollection result1 = serviceProxy.RetrieveMultiple(query);
if (result1.Entities.Count > 0)
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('valid Username and Password')</script>");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('invalid Username and Password')</script>");
}
}
}
}
}
ref :
http://mileyja.blogspot.in/2011/07/convert-queryexpression-to-fetchxml.html
http://stackoverflow.com/questions/8669611/how-to-write-queryexpression-for-following-query
http://msdn.microsoft.com/en-us/library/gg334688.aspx
OptionSetValue osv = (OptionSetValue)entities.Attributes["statuscode"];
if (osv.Value == 1)
{
dr["Order Status"] = "New";
}
if (osv.Value == 2)
{
dr["Order Status"] = "Pending";
}
//dr["Order Status"] = osv.Value;
for optional set value
No comments:
Post a Comment