您好,首先不知道您有没有仔细看我昨天给你的图说明,如果你的两个数据集在同一个数据源中,那么使用Joinitem,如果不在同一个数据源,使用Linkitem,但是Linkitem不支持UDB,PG,DB2数据源。
另外既然是外接表,要查询出结果,肯定需要设置返回的结果字段才行(QueryParameter.ResultFields)。下面附上我亲测有效代码(Joinitem):
DatasetVector dataset1 = workspace.Datasources[0].Datasets["New_Point_1"] as DatasetVector;
DatasetVector dataset2 = workspace.Datasources[0].Datasets["New_Point_2"] as DatasetVector;
JoinItem joinitem = new JoinItem();
String foreignTableName = dataset2.TableName;
// 设置连接信息类的属性
joinitem.ForeignTable = foreignTableName;
joinitem.JoinFilter =dataset1.TableName+ ".id=" + foreignTableName + ".id";
joinitem.JoinType = JoinType.LeftJoin;
joinitem.Name = "Connect";
// 设置连接信息集合类,将连接信息加入到连接信息集合中
JoinItems joinitems = new JoinItems();
joinitems.Add(joinitem);
QueryParameter query = new QueryParameter();
query.JoinItems = joinitems;
string[] result=new string[2];
string r1 = dataset1.Name + ".SmID";
string r2 = dataset2.Name + ".KMP";
result[0] = r1;
result[1] = r2;
query.AttributeFilter =dataset1.TableName+".SmID=2";
query.ResultFields = result;
Recordset re= dataset1.Query(query);