Link to home
Start Free TrialLog in
Avatar of ochangc
ochangc

asked on

retrieving CRM 4 data

I am new to microsoft CRM. I have been able to connect froman aspx page that I created, I now need to populate a grid with CRM data. What is the  best mmethod for this
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Hi cmm4,

I suggest you download CRM SDK from : http://www.microsoft.com/downloadS/details.aspx?FamilyID=82e632a7-faf9-41e0-8ec1-a2662aae9dfb

One of the most common method is listed here : http://technet.microsoft.com/en-us/library/aa680437.aspx

There are two other methods which you might want to check in SDK apart from QueryByExpression
they are:
1. FetchXml
2. QueryByAttribute

I recommend you start with QueryByExpression first and then move further.

Let me know if you have any questions on the same.

Regards,
Chinmay.
Kindly refer to : http://msdn.microsoft.com/en-us/library/bb929002.aspx
The code I sent is for 3.0 and will not work with 4.0.
Avatar of ochangc
ochangc

ASKER

Ok, this is all good. now how do i post this to a grid to view?
Once you get results back from CRM you can loop through the resultant BusinessEntityCollection and either create a dataset or bettter a List<T> or a custom array. Once that is done you can bind it to the gridview by setting gridview's datasource property.
Avatar of ochangc

ASKER

Thanks, could you post an example. I have been trying all sorts of things and I am spent. The powers to be are need happy in the least. Once again thanks.
Here is a ... pseudo code not sure whether it will compile or not, but this is to give you an idea, you can process the data in many ways.


 if (collection.BusinessEntities.Length > 0)
            {
            List<Account> accounts = new List<Account>();
            foreach(accountRecord in collection.BusinessEntities.BusinessEntities)
            {
                      Account accountInstance = new Account{Name = accountRecord.name};
                  accounts.Add(accountInstance);
            }
            
            gridView.DataSource = accounts;
            gridView.AutoGenerateColumns = true;
            gridView.DataBind();                            

            }

// DTO to mimic CRM entity
class Account
{
public string Name {get; set;}
}
Avatar of ochangc

ASKER

This is what I get

An exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll but was not handled in user code

Additional information: Server was unable to process request.

It happens right on this line
   RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)service.Execute(attributeRequest);
And when I add an exception handler it says
server was unable to handle request

Helllp!
ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial