SP 2010 Getting Started With BCS
-
Upload
sreedhar-konduru -
Category
Documents
-
view
223 -
download
0
Transcript of SP 2010 Getting Started With BCS
-
7/27/2019 SP 2010 Getting Started With BCS
1/36
SP 2010: Getting started with Business Connectivity Services (BCS) in
SharePoint 2010
Author: Tobias Zimmergren
http://www.zimmergren.net |http://www.tozit.com |@zimmergren
Introduction
Article 1 in the small BCS-series:
1. SP 2010: Getting started with the Business Connectivity Services (BCS)
2. SP 2010: Programmatically work with External Lists (BCS) in SharePoint 2010
3.SP 2010: Programmatically work with External Lists (BCS) using the Client Object Model
BCS in SharePoint 2010 is an awesome refinement of the Business Data Catalog from MOSS
2007. With BCS - or Business Connectivity Services - you get the possibility to connect external
data and work with it from SharePoint.
In this article I will not cover the basics of what BCS is all about (MSDN/TechNet does this very
well) - I will rather give you a walkthrough of how you can setup a BCS connection to an external
database, and then work with this information directly from a SharePoint list - without the user
actually knowing anything about the connection to the database.
A sample SQL database
I'll just show you how my sample database is set up - simply create a new database in your SQLServer and have it filled with some example data. In my case, this is the data in my SQL
http://www.zimmergren.net/http://www.zimmergren.net/http://www.tozit.com/http://www.twitter.com/zimmergrenhttp://www.zimmergren.net/archive/2010/01/19/sp-2010-programmatically-work-with-external-lists-bcs-in-sharepoint-2010.aspxhttp://www.zimmergren.net/archive/2010/01/21/sp-2010-programmatically-work-with-external-lists-bcs-using-the-client-object-model.aspxhttp://technet.microsoft.com/en-us/library/ee661740(office.14).aspxhttp://technet.microsoft.com/en-us/library/ee661740(office.14).aspxhttp://www.zimmergren.net/archive/2010/01/21/sp-2010-programmatically-work-with-external-lists-bcs-using-the-client-object-model.aspxhttp://www.zimmergren.net/archive/2010/01/19/sp-2010-programmatically-work-with-external-lists-bcs-in-sharepoint-2010.aspxhttp://www.twitter.com/zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/http://www.zimmergren.net/ -
7/27/2019 SP 2010 Getting Started With BCS
2/36
database,calledZimmergren_DB:
In this sample database, I've added a table called ProductListwhich in theory will represent
some products in this database, like this:
I'm filling the database with some sample data, so we will be familiar with this data when we
later watch this information from SharePoint:
Alright - we have some sample data in our SQL Server. Nothing fancy, just some very simple
data. Great, let's get going with the fun stuff!
Creating an external content type
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_6_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_4_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_2_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_6_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_4_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_2_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_6_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_4_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_2_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
3/36
The most effective and easy way to set up a simple BCS connection is to use SharePoint
Designer 2010. You heard me, we can now get up and running with BCS by using SPD instead of
modeling complex ADF files and things like that.
In order to do this, we need to create a newExternal Content Type!
Here's how do create our External Content Type and hook it up with our database, step by step:
Open the site you want to work with using SharePoint Designer 2010Select "External Content Types" in the left hand navigation:
Loading this page might take some time, be patient!
http://www.microsoft.com/spdhttp://www.microsoft.com/spdhttp://msdn.microsoft.com/en-us/library/ee556391(office.14).aspxhttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_8_0A7867A4.pnghttp://msdn.microsoft.com/en-us/library/ee556391(office.14).aspxhttp://www.microsoft.com/spdhttp://www.microsoft.com/spd -
7/27/2019 SP 2010 Getting Started With BCS
4/36
Click to create a new External Content Type like this:
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_10_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
5/36
Click the link that reads: "Click here to discover external data sources and defineoperations":
Click "Add Connection"
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_14_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_12_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_14_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_12_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
6/36
Select "SQL Server" as your Data Source Type:
Enter the details about your connection to your SQL Server:
When the connection is made, your Data Source Explorer will be filled with thedatabase you have specified. Now choose the table you want to work with, and right-
click and select "Create All Operations":
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_18_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_16_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_18_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_16_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
7/36
You'll be presented with a wizard-like dialog where you can specify the operations,elements and other properties for your BCS connection.
Click "Next" to get to the ParameterspageSelect the field that you want to act as an Identifier. In my case I've selected my
ProductID just to get on with it:
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_22_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_20_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_22_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_20_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
8/36
Click "Finish"You'll be presented with a list of operations that your External Content Type can do, like
this:
That's it. A few points, a few clicks - and you're done. Let's create an external list (using the
Browser to show how simple it is..) and hook up our external content type with it!
Creating an external list
There's a few ways to create an external list in SharePoint 2010. We will create it using the
Browser UI to show you how simple it can be.
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_24_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
9/36
Open your site and choose Site Actions - More Options
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_26_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
10/36
Select the External List template, and click Create
Enter a name for your list, e.g. Product List You'll see a field in this list called External Content Type, click the browse-button
beside it:
What is really awesome here, is that you're now presented with a dialog where you
simply can choose the data source for this list. That means, you'll select the data
source you've created (mine is called Zimmergren_DB). Then your list will
automatically work against the SQL database, but still have the look and feel of a
SharePoint 2010 list.
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_30_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_28_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_30_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_28_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
11/36
Select your data source and click OK:
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_32_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
12/36
Now simply click the button called Create:
Would you look at that! You're now working with external data, from your (what looks to be)
normal SharePoint list! This is brilliant!
You now have the ability to create new items, update existing items, delete items and do all your
normal CRUD-operations (CRUD = Create, Read, Update, Delete) straight from the SharePoint
2010 list.
Proof of concept - Adding a new product
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_34_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
13/36
Let's just for the fun of it add a new product called "Awesome Product 1.0" like the following
screenshot:
Now go to your SQL Server and see the changes take effect immediately. The data is NOT stored
in SharePoint, it's stored in your SQL Database.
This is what my table now looks like in the SQL Server, after adding a new item in the
SharePoint list:
Summary
With a few points, followed by a few clicks - you've set up your external data connection.
Basicallyit's that simple.
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_38_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_36_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_38_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_36_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
14/36
42271097714 0 False
none 0x68F81BE0C3F Brow se
Brow se false /w EPDw UBMA9k/w EWCALw npq
Home Contact
About Tobias
Tobias Zimmergren's thoughts on developmentMicrosoft MVP, SharePointEasily Secure SharePoint Documents
Based on Metadata. By Titus Labs.
Free SharePoint Monitoring Tool
With E-mail Alerts, Performance Monitor
by Idera. Download it now!
Free SharePoint Reader
Take SharePoint Offline
Sync SharePoint to Laptop!
Chat with me if I'm online!
search blog
most popular
recent posts
SharePoint Evolution Conference, London
SharePoint 2010 - The Developer Tour (Sweden)
SP 2010: SharePoint Server 2010 - Creating a custom Document ID provider
SP 2010: Site Collection Keep-Alive Job now available by AC
SP 2010: Certification exam details for SharePoint 2010 published
tag cloud
http://www.zimmergren.net/http://www.zimmergren.net/http://www.zimmergren.net/contact.aspxhttp://www.zimmergren.net/contact.aspxhttp://www.zimmergren.net/about.aspxhttp://www.zimmergren.net/about.aspxhttp://www.zimmergren.net/http://www.zimmergren.net/http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=453be0f4&a_rid=cdc1b7dahttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=453be0f4&a_rid=cdc1b7dahttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=ac43d413http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=64bfaeddhttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=64bfaeddhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://www.zimmergren.net/archive/2010/04/22/sharepoint-evolution-conference-london.aspxhttp://www.zimmergren.net/archive/2010/04/15/sharepoint-2010-the-developer-tour-sweden.aspxhttp://www.zimmergren.net/archive/2010/04/13/sp-2010-sharepoint-server-2010-creating-your-custom-document-id-provider.aspxhttp://www.zimmergren.net/archive/2010/03/29/sp-2010-site-collection-keep-alive-job-now-available-by-ac.aspxhttp://www.zimmergren.net/archive/2010/03/28/sp-2010-certification-exam-details-for-sharepoint-2010-published.aspxhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://signup.alerts.live.com/alerts/login.do?PINID=41953394&returnURL=http://www.zimmergren.nethttps://mvp.support.microsoft.com/profile/Zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/rss.xmlhttp://www.zimmergren.net/archive/2010/03/28/sp-2010-certification-exam-details-for-sharepoint-2010-published.aspxhttp://www.zimmergren.net/archive/2010/03/29/sp-2010-site-collection-keep-alive-job-now-available-by-ac.aspxhttp://www.zimmergren.net/archive/2010/04/13/sp-2010-sharepoint-server-2010-creating-your-custom-document-id-provider.aspxhttp://www.zimmergren.net/archive/2010/04/15/sharepoint-2010-the-developer-tour-sweden.aspxhttp://www.zimmergren.net/archive/2010/04/22/sharepoint-evolution-conference-london.aspxhttp://settings.messenger.live.com/Conversation/[email protected]&mkt=en-UShttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=64bfaeddhttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=ac43d413http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=453be0f4&a_rid=cdc1b7dahttp://www.zimmergren.net/http://www.zimmergren.net/about.aspxhttp://www.zimmergren.net/contact.aspxhttp://www.zimmergren.net/ -
7/27/2019 SP 2010 Getting Started With BCS
15/36
.NET 3.5, 2010,AJAX, BCS,BDC, Blogging,Branding, CAML,Certifications, Client Object Model,Custom Search, Forum Web Part,HitHighlighting, How To,Indexing, Links,LINQ, LINQ to SharePoint,
Master Page, MCTS,Microsoft Online Services, MOSS 2007,Queries, Search,Search Query
Object Model, Search Results Page, Search Scope,
SharePoint,SharePoint Designer,SharePoint Online,
Silverlight, SP2010,Sweden SharePoint User Group, Tips,Tools, Training,UserControls,
WSS 3.0, XSLT,archives
September 2006 (3)
October 2006 (2)
November 2006 (2)
December 2006 (2)
January 2007 (1)
February 2007 (7)
March 2007 (1)
April 2007 (4)May 2007 (1)
June 2007 (4)
December 2007 (2)
August 2007 (3)
September 2007 (2)
October 2007 (2)
November 2007 (2)
January 2008 (3)
March 2008 (10)
February 2008 (1)
April 2008 (9)
May 2008 (5)June 2008 (2)
July 2008 (4)
August 2008 (2)
September 2008 (4)
October 2008 (6)
November 2008 (8)
December 2008 (1)
January 2009 (6)
February 2009 (7)
March 2009 (5)
April 2009 (9)
May 2009 (5)June 2009 (6)
July 2009 (7)
August 2009 (6)
September 2009 (3)
October 2009 (3)
November 2009 (2)
December 2009 (3)
http://www.zimmergren.net/archive/tags/.NET%203.5/default.aspxhttp://www.zimmergren.net/archive/tags/.NET%203.5/default.aspxhttp://www.zimmergren.net/archive/tags/AJAX/default.aspxhttp://www.zimmergren.net/archive/tags/AJAX/default.aspxhttp://www.zimmergren.net/archive/tags/BDC/default.aspxhttp://www.zimmergren.net/archive/tags/BDC/default.aspxhttp://www.zimmergren.net/archive/tags/Branding/default.aspxhttp://www.zimmergren.net/archive/tags/Branding/default.aspxhttp://www.zimmergren.net/archive/tags/Branding/default.aspxhttp://www.zimmergren.net/archive/tags/Certifications/default.aspxhttp://www.zimmergren.net/archive/tags/Certifications/default.aspxhttp://www.zimmergren.net/archive/tags/Certifications/default.aspxhttp://www.zimmergren.net/archive/tags/Custom%20Search/default.aspxhttp://www.zimmergren.net/archive/tags/HitHighlighting/default.aspxhttp://www.zimmergren.net/archive/tags/HitHighlighting/default.aspxhttp://www.zimmergren.net/archive/tags/HitHighlighting/default.aspxhttp://www.zimmergren.net/archive/tags/Indexing/default.aspxhttp://www.zimmergren.net/archive/tags/Indexing/default.aspxhttp://www.zimmergren.net/archive/tags/Indexing/default.aspxhttp://www.zimmergren.net/archive/tags/LINQ/default.aspxhttp://www.zimmergren.net/archive/tags/LINQ/default.aspxhttp://www.zimmergren.net/archive/tags/LINQ/default.aspxhttp://www.zimmergren.net/archive/tags/Master%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/Master%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/Microsoft%20Online%20Services/default.aspxhttp://www.zimmergren.net/archive/tags/Microsoft%20Online%20Services/default.aspxhttp://www.zimmergren.net/archive/tags/Queries/default.aspxhttp://www.zimmergren.net/archive/tags/Queries/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Query%20Object%20Model/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Query%20Object%20Model/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Query%20Object%20Model/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Results%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Results%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Results%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/SharePoint/default.aspxhttp://www.zimmergren.net/archive/tags/SharePoint/default.aspxhttp://www.zimmergren.net/archive/tags/SharePoint/default.aspxhttp://www.zimmergren.net/archive/tags/SharePoint%20Online/default.aspxhttp://www.zimmergren.net/archive/tags/SharePoint%20Online/default.aspxhttp://www.zimmergren.net/archive/tags/Silverlight/default.aspxhttp://www.zimmergren.net/archive/tags/Silverlight/default.aspxhttp://www.zimmergren.net/archive/tags/Sweden%20SharePoint%20User%20Group/default.aspxhttp://www.zimmergren.net/archive/tags/Sweden%20SharePoint%20User%20Group/default.aspxhttp://www.zimmergren.net/archive/tags/Sweden%20SharePoint%20User%20Group/default.aspxhttp://www.zimmergren.net/archive/tags/Tools/default.aspxhttp://www.zimmergren.net/archive/tags/Tools/default.aspxhttp://www.zimmergren.net/archive/tags/Tools/default.aspxhttp://www.zimmergren.net/archive/tags/UserControls/default.aspxhttp://www.zimmergren.net/archive/tags/UserControls/default.aspxhttp://www.zimmergren.net/archive/tags/WSS%203.0/default.aspxhttp://www.zimmergren.net/archive/tags/WSS%203.0/default.aspxhttp://www.zimmergren.net/archive/2006/09.aspxhttp://www.zimmergren.net/archive/2006/10.aspxhttp://www.zimmergren.net/archive/2006/11.aspxhttp://www.zimmergren.net/archive/2006/12.aspxhttp://www.zimmergren.net/archive/2007/01.aspxhttp://www.zimmergren.net/archive/2007/02.aspxhttp://www.zimmergren.net/archive/2007/03.aspxhttp://www.zimmergren.net/archive/2007/04.aspxhttp://www.zimmergren.net/archive/2007/05.aspxhttp://www.zimmergren.net/archive/2007/06.aspxhttp://www.zimmergren.net/archive/2007/12.aspxhttp://www.zimmergren.net/archive/2007/08.aspxhttp://www.zimmergren.net/archive/2007/09.aspxhttp://www.zimmergren.net/archive/2007/10.aspxhttp://www.zimmergren.net/archive/2007/11.aspxhttp://www.zimmergren.net/archive/2008/01.aspxhttp://www.zimmergren.net/archive/2008/03.aspxhttp://www.zimmergren.net/archive/2008/02.aspxhttp://www.zimmergren.net/archive/2008/04.aspxhttp://www.zimmergren.net/archive/2008/05.aspxhttp://www.zimmergren.net/archive/2008/06.aspxhttp://www.zimmergren.net/archive/2008/07.aspxhttp://www.zimmergren.net/archive/2008/08.aspxhttp://www.zimmergren.net/archive/2008/09.aspxhttp://www.zimmergren.net/archive/2008/10.aspxhttp://www.zimmergren.net/archive/2008/11.aspxhttp://www.zimmergren.net/archive/2008/12.aspxhttp://www.zimmergren.net/archive/2009/01.aspxhttp://www.zimmergren.net/archive/2009/02.aspxhttp://www.zimmergren.net/archive/2009/03.aspxhttp://www.zimmergren.net/archive/2009/04.aspxhttp://www.zimmergren.net/archive/2009/05.aspxhttp://www.zimmergren.net/archive/2009/06.aspxhttp://www.zimmergren.net/archive/2009/07.aspxhttp://www.zimmergren.net/archive/2009/08.aspxhttp://www.zimmergren.net/archive/2009/09.aspxhttp://www.zimmergren.net/archive/2009/10.aspxhttp://www.zimmergren.net/archive/2009/11.aspxhttp://www.zimmergren.net/archive/2009/12.aspxhttp://www.zimmergren.net/archive/2009/12.aspxhttp://www.zimmergren.net/archive/2009/11.aspxhttp://www.zimmergren.net/archive/2009/10.aspxhttp://www.zimmergren.net/archive/2009/09.aspxhttp://www.zimmergren.net/archive/2009/08.aspxhttp://www.zimmergren.net/archive/2009/07.aspxhttp://www.zimmergren.net/archive/2009/06.aspxhttp://www.zimmergren.net/archive/2009/05.aspxhttp://www.zimmergren.net/archive/2009/04.aspxhttp://www.zimmergren.net/archive/2009/03.aspxhttp://www.zimmergren.net/archive/2009/02.aspxhttp://www.zimmergren.net/archive/2009/01.aspxhttp://www.zimmergren.net/archive/2008/12.aspxhttp://www.zimmergren.net/archive/2008/11.aspxhttp://www.zimmergren.net/archive/2008/10.aspxhttp://www.zimmergren.net/archive/2008/09.aspxhttp://www.zimmergren.net/archive/2008/08.aspxhttp://www.zimmergren.net/archive/2008/07.aspxhttp://www.zimmergren.net/archive/2008/06.aspxhttp://www.zimmergren.net/archive/2008/05.aspxhttp://www.zimmergren.net/archive/2008/04.aspxhttp://www.zimmergren.net/archive/2008/02.aspxhttp://www.zimmergren.net/archive/2008/03.aspxhttp://www.zimmergren.net/archive/2008/01.aspxhttp://www.zimmergren.net/archive/2007/11.aspxhttp://www.zimmergren.net/archive/2007/10.aspxhttp://www.zimmergren.net/archive/2007/09.aspxhttp://www.zimmergren.net/archive/2007/08.aspxhttp://www.zimmergren.net/archive/2007/12.aspxhttp://www.zimmergren.net/archive/2007/06.aspxhttp://www.zimmergren.net/archive/2007/05.aspxhttp://www.zimmergren.net/archive/2007/04.aspxhttp://www.zimmergren.net/archive/2007/03.aspxhttp://www.zimmergren.net/archive/2007/02.aspxhttp://www.zimmergren.net/archive/2007/01.aspxhttp://www.zimmergren.net/archive/2006/12.aspxhttp://www.zimmergren.net/archive/2006/11.aspxhttp://www.zimmergren.net/archive/2006/10.aspxhttp://www.zimmergren.net/archive/2006/09.aspxhttp://www.zimmergren.net/archive/tags/WSS%203.0/default.aspxhttp://www.zimmergren.net/archive/tags/WSS%203.0/default.aspxhttp://www.zimmergren.net/archive/tags/UserControls/default.aspxhttp://www.zimmergren.net/archive/tags/Tools/default.aspxhttp://www.zimmergren.net/archive/tags/Tools/default.aspxhttp://www.zimmergren.net/archive/tags/Sweden%20SharePoint%20User%20Group/default.aspxhttp://www.zimmergren.net/archive/tags/Sweden%20SharePoint%20User%20Group/default.aspxhttp://www.zimmergren.net/archive/tags/Silverlight/default.aspxhttp://www.zimmergren.net/archive/tags/Silverlight/default.aspxhttp://www.zimmergren.net/archive/tags/SharePoint%20Online/default.aspxhttp://www.zimmergren.net/archive/tags/SharePoint/default.aspxhttp://www.zimmergren.net/archive/tags/SharePoint/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Results%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Results%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Query%20Object%20Model/default.aspxhttp://www.zimmergren.net/archive/tags/Search%20Query%20Object%20Model/default.aspxhttp://www.zimmergren.net/archive/tags/Queries/default.aspxhttp://www.zimmergren.net/archive/tags/Queries/default.aspxhttp://www.zimmergren.net/archive/tags/Microsoft%20Online%20Services/default.aspxhttp://www.zimmergren.net/archive/tags/Microsoft%20Online%20Services/default.aspxhttp://www.zimmergren.net/archive/tags/Master%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/Master%20Page/default.aspxhttp://www.zimmergren.net/archive/tags/LINQ/default.aspxhttp://www.zimmergren.net/archive/tags/LINQ/default.aspxhttp://www.zimmergren.net/archive/tags/Indexing/default.aspxhttp://www.zimmergren.net/archive/tags/Indexing/default.aspxhttp://www.zimmergren.net/archive/tags/HitHighlighting/default.aspxhttp://www.zimmergren.net/archive/tags/HitHighlighting/default.aspxhttp://www.zimmergren.net/archive/tags/Custom%20Search/default.aspxhttp://www.zimmergren.net/archive/tags/Custom%20Search/default.aspxhttp://www.zimmergren.net/archive/tags/Certifications/default.aspxhttp://www.zimmergren.net/archive/tags/Certifications/default.aspxhttp://www.zimmergren.net/archive/tags/Branding/default.aspxhttp://www.zimmergren.net/archive/tags/Branding/default.aspxhttp://www.zimmergren.net/archive/tags/BDC/default.aspxhttp://www.zimmergren.net/archive/tags/BDC/default.aspxhttp://www.zimmergren.net/archive/tags/AJAX/default.aspxhttp://www.zimmergren.net/archive/tags/AJAX/default.aspxhttp://www.zimmergren.net/archive/tags/.NET%203.5/default.aspxhttp://www.zimmergren.net/archive/tags/.NET%203.5/default.aspx -
7/27/2019 SP 2010 Getting Started With BCS
16/36
January 2010 (7)
February 2010 (2)
March 2010 (6)
April 2010 (3)
blogroll
MVP: Liam Cleary
MVP: Ton Stegeman
MVP: Todd Baginski
MVP: Nick Swan
MVP: Jan Tielens
MVP: Heather Solomon
Joel Oleson
MSFT: Pontus Haglund
MVP: Vincent Rothwell
MVP: Zlatan
Daniel McPhearson
Mark Schneider
MSFT: Team Blog
MVP: Andrew Woody
MVP: Andrew Connell
MVP: Daniel Brown
MVP: Eric Schupps
MVP: Spence Harbar
MVP: Muhanad Omar
MVP: Waldek Mastyrkarz
Goodies
Easily Secure SharePoint Documents
Based on Metadata. By Titus Labs.
Free SharePoint Monitoring Tool
With E-mail Alerts, Performance Monitor
by Idera. Download it now!
Free SharePoint Reader
Take SharePoint Offline
Sync SharePoint to Laptop!
Backup SharePoint. Free Trial.
High performance SharePoint
backup and recovery.
http://www.zimmergren.net/archive/2010/01.aspxhttp://www.zimmergren.net/archive/2010/02.aspxhttp://www.zimmergren.net/archive/2010/03.aspxhttp://www.zimmergren.net/archive/2010/04.aspxhttp://www.helloitsliam.com/http://www.tonstegeman.com/Blog/default.aspxhttp://www.toddbaginski.com/bloghttp://www.sharepointnick.com/blog/default.aspxhttp://weblogs.asp.net/jan/rss.aspxhttp://heathersolomon.com/blog/Default.aspxhttp://www.sharepointjoel.com/http://sharepoint.microsoft.com/blogs/pontush/default.aspxhttp://blog.thekid.me.uk/http://dotnet.org.za/zlatan/default.aspxhttp://community.zevenseas.com/Blogs/Daniel/default.aspxhttp://www.sharepointplan.com/mark_schneiders_sharepoin/http://blogs.msdn.com/sharepoint/default.aspxhttp://www.21apps.com/http://andrewconnell.com/blog/Default.aspxhttp://www.danielbrown.id.au/default.aspxhttp://www.binarywave.com/blogs/eshupps/default.aspxhttp://www.harbar.net/Default.aspxhttp://geeksconnected.com/muhanad/default.aspxhttp://blog.mastykarz.nl/http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=453be0f4&a_rid=cdc1b7dahttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=453be0f4&a_rid=cdc1b7dahttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=ac43d413http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=64bfaeddhttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=64bfaeddhttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=be0e070ahttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=be0e070ahttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=f42bda28http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=f42bda28http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=f42bda28http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=f42bda28http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=f42bda28http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=f42bda28http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=be0e070ahttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=64bfaeddhttp://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=ac43d413http://sharepointads.com/members/scripts/click.php?a_aid=tosigt&a_bid=453be0f4&a_rid=cdc1b7dahttp://blog.mastykarz.nl/http://geeksconnected.com/muhanad/default.aspxhttp://www.harbar.net/Default.aspxhttp://www.binarywave.com/blogs/eshupps/default.aspxhttp://www.danielbrown.id.au/default.aspxhttp://andrewconnell.com/blog/Default.aspxhttp://www.21apps.com/http://blogs.msdn.com/sharepoint/default.aspxhttp://www.sharepointplan.com/mark_schneiders_sharepoin/http://community.zevenseas.com/Blogs/Daniel/default.aspxhttp://dotnet.org.za/zlatan/default.aspxhttp://blog.thekid.me.uk/http://sharepoint.microsoft.com/blogs/pontush/default.aspxhttp://www.sharepointjoel.com/http://heathersolomon.com/blog/Default.aspxhttp://weblogs.asp.net/jan/rss.aspxhttp://www.sharepointnick.com/blog/default.aspxhttp://www.toddbaginski.com/bloghttp://www.tonstegeman.com/Blog/default.aspxhttp://www.helloitsliam.com/http://www.zimmergren.net/archive/2010/04.aspxhttp://www.zimmergren.net/archive/2010/03.aspxhttp://www.zimmergren.net/archive/2010/02.aspxhttp://www.zimmergren.net/archive/2010/01.aspx -
7/27/2019 SP 2010 Getting Started With BCS
17/36
SP 2010: Getting started with Business Connectivity Services (BCS) inSharePoint 2010
Author: Tobias Zimmergren
http://www.zimmergren.net |http://www.tozit.com |@zimmergren
Introduction
Article 1 in the small BCS-series:
1. SP 2010: Getting started with the Business Connectivity Services (BCS)
2. SP 2010: Programmatically work with External Lists (BCS) in SharePoint 2010
3.SP 2010: Programmatically work with External Lists (BCS) using the Client Object Model
BCS in SharePoint 2010 is an awesome refinement of the Business Data Catalog from MOSS
2007. With BCS - or Business Connectivity Services - you get the possibility to connect external
data and work with it from SharePoint.
In this article I will not cover the basics of what BCS is all about (MSDN/TechNet does this very
well) - I will rather give you a walkthrough of how you can setup a BCS connection to an external
database, and then work with this information directly from a SharePoint list - without the user
actually knowing anything about the connection to the database.
http://www.zimmergren.net/http://www.zimmergren.net/http://www.tozit.com/http://www.twitter.com/zimmergrenhttp://www.zimmergren.net/archive/2010/01/19/sp-2010-programmatically-work-with-external-lists-bcs-in-sharepoint-2010.aspxhttp://www.zimmergren.net/archive/2010/01/21/sp-2010-programmatically-work-with-external-lists-bcs-using-the-client-object-model.aspxhttp://technet.microsoft.com/en-us/library/ee661740(office.14).aspxhttp://technet.microsoft.com/en-us/library/ee661740(office.14).aspxhttp://www.zimmergren.net/archive/2010/01/21/sp-2010-programmatically-work-with-external-lists-bcs-using-the-client-object-model.aspxhttp://www.zimmergren.net/archive/2010/01/19/sp-2010-programmatically-work-with-external-lists-bcs-in-sharepoint-2010.aspxhttp://www.twitter.com/zimmergrenhttp://www.tozit.com/http://www.zimmergren.net/http://www.zimmergren.net/ -
7/27/2019 SP 2010 Getting Started With BCS
18/36
BCS Poster: Business Connectivity Services Poster
BCS Team Blog:http://blogs.msdn.com/bcs/
A sample SQL database
I'll just show you how my sample database is set up - simply create a new database in your SQL
Server and have it filled with some example data. In my case, this is the data in my SQL
database, called Zimmergren_DB:
In this sample database, I've added a table called ProductListwhich in theory will represent
some products in this database, like this:
I'm filling the database with some sample data, so we will be familiar with this data when we
later watch this information from SharePoint:
http://www.microsoft.com/downloads/details.aspx?FamilyID=73F5A648-9BF6-413A-83D9-1D1BA1B5B599&displaylang=en#filelisthttp://blogs.msdn.com/bcs/http://www.zimmergren.net/Lists/Posts/Attachments/177/image_6_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_4_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_2_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_6_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_4_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_2_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_6_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_4_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_2_0A7867A4.pnghttp://blogs.msdn.com/bcs/http://www.microsoft.com/downloads/details.aspx?FamilyID=73F5A648-9BF6-413A-83D9-1D1BA1B5B599&displaylang=en#filelist -
7/27/2019 SP 2010 Getting Started With BCS
19/36
Alright - we have some sample data in our SQL Server. Nothing fancy, just some very simple
data. Great, let's get going with the fun stuff!
Creating an external content type
The most effective and easy way to set up a simple BCS connection, is to use SharePoint
Designer 2010. You heard me, we can now get up and running with BCS by using SPD instead of
modeling complex ADF files and things like that.
In order to do this, we need to create a newExternal Content Type!
Here's how do create our External Content Type and hook it up with our database, step by step:
Open the site you want to work with using SharePoint Designer 2010
http://www.microsoft.com/spdhttp://www.microsoft.com/spdhttp://msdn.microsoft.com/en-us/library/ee556391(office.14).aspxhttp://msdn.microsoft.com/en-us/library/ee556391(office.14).aspxhttp://www.microsoft.com/spdhttp://www.microsoft.com/spd -
7/27/2019 SP 2010 Getting Started With BCS
20/36
Select "External Content Types" in the left hand navigation:
Loading this page might take some time, be patient!
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_8_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
21/36
Click to create a new External Content Type like this:
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_10_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
22/36
Click the link that reads: "Click here to discover external data sources and defineoperations":
Click "Add Connection"
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_14_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_12_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_14_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_12_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
23/36
Select "SQL Server" as your Data Source Type:
Enter the details about your connection to your SQL Server:
When the connection is made, your Data Source Explorer will be filled with thedatabase you have specified. Now choose the table you want to work with, and right-
click and select "Create All Operations":
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_18_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_16_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_18_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_16_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
24/36
You'll be presented with a wizard-like dialog where you can specify the operations,elements and other properties for your BCS connection.
Click "Next" to get to the ParameterspageSelect the field that you want to act as an Identifier. In my case I've selected my
ProductID just to get on with it:
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_22_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_20_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_22_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_20_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
25/36
Click "Finish"You'll be presented with a list of operations that your External Content Type can do, like
this:
That's it. A few points, a few clicks - and you're done. Let's create an external list (using the
Browser to show how simple it is..) and hook up our external content type with it!
Creating an external list
There's a few ways to create an external list in SharePoint 2010. We will create it using the
Browser UI to show you how simple it can be.
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_24_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
26/36
Open your site and choose Site Actions - More Options
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_26_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
27/36
Select the External List template, and click Create
Enter a name for your list, e.g. Product ListYou'll see a field in this list called External Content Type, click the browse-button
beside it:
What is really awesome here, is that you're now presented with a dialog where you
simply can choose the data source for this list. That means, you'll select the data
source you've created (mine is called Zimmergren_DB). Then your list will
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_30_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_28_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_30_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_28_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
28/36
automatically work against the SQL database, but still have the look and feel of a
SharePoint 2010 list.
Select your data source and click OK:
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_32_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
29/36
Now simply click the button called Create:
Would you look at that! You're now working with external data, from your (what looks to be)
normal SharePoint list! This is brilliant!
You now have the ability to create new items, update existing items, delete items and do all your
normal CRUD-operations (CRUD = Create, Read, Update, Delete) straight from the SharePoint
2010 list.
Proof of concept - Adding a new product
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_34_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
30/36
Let's just for the fun of it add a new product called "Awesome Product 1.0" like the following
screenshot:
Now go to your SQL Server and see the changes take effect immediately. The data is NOT stored
in SharePoint, it's stored in your SQL Database.
This is what my table now looks like in the SQL Server, after adding a new item in the
SharePoint list:
Summary
With a few points, followed by a few clicks - you've set up your external data connection.
Basicallyit's that simple.
http://www.zimmergren.net/Lists/Posts/Attachments/177/image_38_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_36_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_38_0A7867A4.pnghttp://www.zimmergren.net/Lists/Posts/Attachments/177/image_36_0A7867A4.png -
7/27/2019 SP 2010 Getting Started With BCS
31/36
Working with data in an External List using the SharePoint Object
Model
The code in this sample doesn't really differ from the way you fetch information from any other
list in SharePoint (2007 or 2010). This - of course - is very welcomed news, as we do not need to
learn any new frameworks or tools to work with the data in our external lists. It simply works as
any other SPList, basically.
Retrieving external data, made simple:
When fetching items from an external list, you can simply do that by utilizing the good-old
SPListobject. We do not need to work with any other types of namespaces or frameworks in
order to do this.
In my SQL Server I've got a table called "ProductList".
This list is filled with the following data:
Fetching some items from the external list, and displaying them in a console app:
// Product List is my external list, that is working with data in the SQL Server!
SPList list=web.Lists["Product List"];
SPQuery q = new SPQuery();
q.Query =
"";
http://www.zimmergren.net/Lists/Posts/Attachments/178/image_4_2017CA45.png -
7/27/2019 SP 2010 Getting Started With BCS
32/36
q.RowLimit = 100;
SPListItemCollection col = list.GetItems(q);
foreach (SPListItem item in col)
Console.WriteLine(item["Name"].ToString());
This will render the following result (fetched from the database):
The things you see in the console windows is fetched straight from the SQL Server (using a BCS
connection through the External List).
Writing data to the External List (hence, writing to the SQL Server)
Seriously, this is way too easy as well...
// Get the external list
SPList list = web.Lists["Product List"];
// Use the traditional approach to create SPListItems and hook it up with the list
SPListItem item = list.Items.Add();
item["Name"] = "Sample Product Wohoo";
-
7/27/2019 SP 2010 Getting Started With BCS
33/36
item["Description"] = "Sample Description Wohoo";
item.Update();
Upon running this code in your SharePoint application, it will create the SPListItem object and
add a Name and Description. When you hit .Update() it will push this data through the datasource connection, to your SQL server.
Here's what the updated data looks like:
Client Object Model code to read from the external list
Just like I described inmy previous article,you now have the awesome ability to work with data in
your External Lists (connected to a data source using BCS)- namely, you can use the standard
SharePoint APIs.
Since I've shown you how you can do this using the ServerObject Model, I thought I could take
another spin at it and show you the code for doing basically the same with the Client Object Model.
The underlying data
As with my previous article, I'm still using the same data source as Iset up in my first article - the
"ProductList" table in my SQL Server database called "Zimmergren_DB"
http://www.zimmergren.net/archive/2010/01/19/sp-2010-programmatically-work-with-external-lists-bcs-in-sharepoint-2010.aspxhttp://www.zimmergren.net/archive/2010/01/18/sp-2010-getting-started-with-business-connectivity-services-bcs-in-sharepoint-2010.aspxhttp://www.zimmergren.net/archive/2010/01/18/sp-2010-getting-started-with-business-connectivity-services-bcs-in-sharepoint-2010.aspxhttp://www.zimmergren.net/archive/2010/01/18/sp-2010-getting-started-with-business-connectivity-services-bcs-in-sharepoint-2010.aspxhttp://www.zimmergren.net/archive/2010/01/18/sp-2010-getting-started-with-business-connectivity-services-bcs-in-sharepoint-2010.aspxhttp://www.zimmergren.net/archive/2010/01/19/sp-2010-programmatically-work-with-external-lists-bcs-in-sharepoint-2010.aspx -
7/27/2019 SP 2010 Getting Started With BCS
34/36
As seen in the SQL Server Management Studio:
Let's fetch the data using a Windows Forms application that utilizes the Client
Object Model!
I've designed a Windows Forms application to utilize the .NET Client Object model (in contrary to using
the Silverlight client object model or JavaScript client object model).
It looks like this:
When you click the fancy button called "Get External Data", it will use the Client Object Model to
fetch the records from the external list (from the SQL server) and display them in a DataGridView.
Nothing fancy.
http://www.zimmergren.net/_attach/image_8_1F06972A.pnghttp://www.zimmergren.net/_attach/image_2_1F06972A.png -
7/27/2019 SP 2010 Getting Started With BCS
35/36
The code!
With no further delays or chit-chat, here's the simple code!
// Define the Client Context (as defined in your textbox)SP.ClientContext context = new SP.ClientContext(tbSite.Text);
SP.Web site = context.Web;
var ProductList = site.Lists.GetByTitle(tbList.Text);
SP.CamlQuery camlQueryAwesomeness = new SP.CamlQuery();
IQueryable productItems =
ProductList.GetItems(camlQueryAwesomeness);
IEnumerable externalList =
context.LoadQuery(productItems);
// This is where we actually execute the request against the server!
context.ExecuteQuery();
// Retrieve the products from the product list using some fancy LINQ
var productListData = from product in externalList
select new
{
// We're never pointing to the field at the 0-index
// because it's used by the BDC Identity itself. Hence our elements start at 1.
ProductID = product.FieldValues.ElementAt(1).Value.ToString(),
ProductName = product.FieldValues.ElementAt(2).Value.ToString(),
ProductDescription = product.FieldValues.ElementAt(3).Value.ToString()
};
// Simply clear the rows and columns of the GridView
gvProducts.Rows.Clear();
gvProducts.Columns.Clear();
// Add the columns we need (ProductID, Name, Description)gvProducts.Columns.Add("ProductID", "ProductID");
gvProducts.Columns.Add("Name", "Product Name");
gvProducts.Columns.Add("Description", "Product Description");
foreach (var product in productListData)
{
// For each product in the list, add a new row to the GridView
-
7/27/2019 SP 2010 Getting Started With BCS
36/36
gvProducts.Rows.Add(
product.ProductID,
product.ProductName,
product.ProductDescription
);
}