Join Operation between layers and data tables in ArcGIS Engine

Source: Internet
Author: User
Before performing the join operation, check that the database can be connected.

Try
{
// Use oledb to connect to the database and the SYS. Basic information table
Iworkspacefactory pworkspacefactory = new oledbworkspacefactory ();
Ipropertyset ppropset = new propertyset ();
Ppropset. setproperty ("connectstring", "provider = sqloledb; Data Source =" + this. instancebox. text + "; initial catalog = sys; user id = sa; Password = sa ;");
Iworkspace pworkspace = pworkspacefactory. Open (ppropset, 0 );
Ifeatureworkspace pfeatureworkspace = (ifeatureworkspace) pworkspace;
Itable pforeigntable = pfeatureworkspace. OpenTable ("SYS. Basic info table ");

// Open temp. mxd that has fixed the data source
Imapdocument pmapdocument = new mapdocumentclass ();
Pmapdocument. Open (startpath + @ "/temp. mxd", null );
IMAP pmap = pmapdocument. get_map (0 );

// Obtain the Layer
Ilayer player = NULL;
For (INT I = 0; I <pmap. layercount; I ++)
{
If (pmap. get_layer (I). Name = "point ")
{
Player = pmap. get_layer (I );
}
}
If (player = NULL)
{
MessageBox. Show ("opening the map file (. mxd) failed ");
Return;
}

// Join
Ifeaturelayer pflayer = (ifeaturelayer) player;
Ifeatureclass pfclass2 = pflayer. featureclass;
Imemoryrelationshipclassfactory pmemrelclassfactory = new memoryrelationshipclassfactoryclass ();
Irelationshipclass prelaclass = pmemrelclassfactory. open ("tablejoin1", pfclass2, "Point Number", (iobjectclass) pforeigntable, "Point Number", "forward", "backward", esrirelcardinality. esrirelcardinalityonetoone );
Idisplayrelationshipclass pdisplayrelationshipc = (idisplayrelationshipclass) pflayer;
Pdisplayrelationshipc. displayrelationshipclass (prelaclass, esrijointype. esrileftouterjoin );
Pmapdocument. Save (false, true );
Pmapdocument. Close ();

}
Catch (system. Exception ex4)
{
MessageBox. Show (ex4.message );
Return;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.