Programatically adding the PGDB to Arcmap

Discussion created by Shrey on Oct 27, 2010
Hello friends i have made mxd and after invoking the mxd I want to set the PGDB resources to the the mxd .  for that I am using the following code :

IObjectFactory objFactory = m_application as IObjectFactory;
                    //Get a reference of the application and make it visible
                    m_application = doc.Parent;
                    m_pMxdocument = m_application.Document as IMxDocument;
                    //path to open the mxd
                    //Hard Coding the path for the mxd

                    m_appHWnd = m_application.hWnd;
                    m_application.Caption = "Accident Location Registration System V 3.0";
                    doc = m_application.Document as MxDocument;


                    //Setting the Data Sources for all the layers

                    pMap = m_pMxdocument.FocusMap;
                    pEnumLayer = pMap.get_Layers(null, false);
                    pLayer = pEnumLayer.Next();
                    //for (int indx = 0; indx < m_pMxdocument.Maps.Count; indx++)
                        while (pLayer != null)
                            pFeatureLayer = pLayer as IFeatureLayer;
                            pFeatclass = pFeatureWorkspace.OpenFeatureClass(pFeatureLayer.Name);
                            pDataLayer = pFeatureLayer as IDataLayer;
                            pDataSetName = pDataLayer.DataSourceName as IDatasetName;
                            pDataSetName.WorkspaceName.PathName = path;
                            pWorkspacename = new WorkspaceNameClass();
                            pWorkspacename.PathName = path;
                            pWorkspacename.ConnectionProperties = pPropset;
                            pWorkspacename.WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory.1";

                            pDataSetName.WorkspaceName = pWorkspacename;
                            pFeatureLayer.FeatureClass = pFeatclass;
                            pLayer = pEnumLayer.Next();

Can any one guide me on this

Thanks You very much .