You are here: Home » Programmatically Accessing BDC Data in Custom Web Parts or User Controls in MOSS 2007

Programmatically Accessing BDC Data in Custom Web Parts or User Controls in MOSS 2007

Posted by sezai
No Comments »

THIS BLOG HAS MOVED !

 THE UPDATED POST CAN BE FOUND HERE –> http://sharepoint-sezai-moss-2007.blogspot.com/2008/02/programmatically-accessing-bdc-data-in.html 

 

The use of BDC columns in lists is a powerful out-of-the-box feature. But what if you want to do it your way and make your own custom BDC user control, or custom BDC Web Part ?

If you need access to data in another system programatically to populate various controls, drop down lists etc. to be used in various pages of your MOSS 2007 site, then the BDC will help you to do just that. If you are working on custom ASP.NET user controls and using them in MOSS 2007 Page Layouts like I am you need to make use of MOSS APIs and assemblies.

I want to programatically access data in a SQL 2000 Database using the BDC!

So I checked out the MOSS 2007 SDK  and followed this example http://msdn2.microsoft.com/en-us/library/ms560143.aspx 

following the example I will populate a DataTable with 2 string DataColumns, Town and the Region the town falls within. I have already created the BDC Application Definition to return the Town data from the external system. The following classes (and their properties or methods) will be used to retrieve this data and get it into my DataTable.

 

ApplicationRegistry

         GetLobSystemInstances()

NamedLobSystemInstanceDictionary

LobSystemInstance

         GetEntities()

Entity

         GetFinderFilters()

         FindFiltered ( FilterCollection,  LobSystemInstance )

FilterCollection          

IEntityInstanceEnumerator          

         MoveNext()

         Current

 


 

NamedLobSystemInstanceDictionary sysInstances = ApplicationRegistry.GetLobSystemInstances();

LobSystemInstance warehouseInstance = sysInstances["WarehouseListDataInstance"];

Entity town = WarehouseListDataInstance.GetEntities()"Town"];

FilterCollection fc = town.GetFinderFilters();

IEntityInstanceEnumerator townEntityInstanceEnumerator = town.FindFiltered(fc, warehouseInstance);

while (townEntityInstanceEnumerator.MoveNext())
      {
               DataRow row = dt.NewRow();
          

 

               IEntityInstance IE = townEntityInstanceEnumerator.Current;

                row["Town"] = IE["Town"].ToString();

                row["Region"] = IE["Region"].ToString();

                dt.Rows.Add(row);       
      }


 

Now I have access to the data I need to use in my User Control.

 

BUT…  I could have also got that data by :

 

1. Hard coding it somewhere, saves time but then you have 2 lists and 2 places to keep data synchronised, depends on the data. (this is may also get you busted and some may shower you with curses)

 

2. ADO.NET it still works and I can still use it in my user control, it may actually be faster to use ADO.NET (hehe). You can still use the classes you all love and have been using for years instead of learning something new. (hey, it takes TIME to learn new stuff!)

 

In comparison to using ADO.NET,

All the backend system connection strings and actual method used to access the backend external data is all within that XML file, the BDC Application Definition file you either hand crafted or used some tool to create.

This provides a programming experience where you access that data through MOSS 2007.

 

Check out the MOSS 2007 SDK for more http://msdn2.microsoft.com/en-us/library/ms549009.aspx

 

THIS BLOG HAS MOVED !

 THE UPDATED POST CAN BE FOUND HERE –> http://sharepoint-sezai-moss-2007.blogspot.com/2008/02/programmatically-accessing-bdc-data-in.html

Your email is never shared.
Required fields are marked *




Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>