Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

Adding a table to an existing table results in wrong link

$
0
0

This is the code being used to add a table to a report:

 

private ISCRTable AddLinkTable(ILinkTable linkTable, string sourceTableAlias, ConnectionInfo connectionInfo)

{ // construct a new Table from its name

ISCRTable newTable = new Table();

newTable.ConnectionInfo = connectionInfo.Clone();

newTable.Name = linkTable.LinkTableName;

newTable.Alias = linkTable.LinkTableName + "_ThisIsTheLinkTable" + LinkTableId++;

if (_dataServiceSettings.DataProvider == DataProvider.Oracle11G)

newTable.QualifiedName = _dataServiceSettings.DatabaseUserName.ToUpper() + "." + newTable.Name.ToUpper();

else

newTable.QualifiedName = "dba." + newTable.Name;

// add a field to this new Table

newTable.DataFields.Add(AddDbField(linkTable.DataField, newTable.Alias));

// join this table to another one named sourceTableAlias, using linkFields TableLink

tableLink = new TableLink();

tableLink.SourceTableAlias = sourceTableAlias;

tableLink.TargetTableAlias = newTable.Alias;

tableLink.JoinType = CrTableJoinTypeEnum.crTableJoinTypeEqualJoin;

Strings sourceFields = new Strings();

Strings targetFields = new Strings();

for (int i = 0; i + 1 < linkTable.LinkFields.Length; i += 2)

{

sourceFields.Add(linkTable.LinkFields[i]); targetFields.Add(linkTable.LinkFields[i + 1]);

}

tableLink.SourceFieldNames = sourceFields;

tableLink.TargetFieldNames = targetFields;

TableLinks tableLinks = new TableLinks();

tableLinks.Add(tableLink); _report.ReportClientDocument.DatabaseController.AddTable(newTable, tableLinks);

_report.ReportClientDocument.DatabaseController.VerifyTableConnectivity(newTable);

//AddFieldToReport("{" + newTable.Alias + "." + linkTable.DataField + "}");

return newTable;

}

 

This is the resulting query SELECT "Article"."ArtId", "Article"."ArtDescr", "ArticleGroup"."AgDescr1", "Article"."ArtPurchLevel", "Article"."ArtMaximum", "Article"."ArtAbc", "Article"."ArtContext", "Article"."ArtPurchPrice", "Article"."ArtServOutUnt", "ArticleSite"."ArtsSitId", "Article"."ArtRecStatus"

FROM  (dba.Article "Article" LEFT OUTER JOIN dba.ArticleGroup "ArticleGroup" ON "Article"."ArtAgId"="ArticleGroup"."AgId")

INNER JOIN "10_78_00"."dba"."ArticleSite" "ArticleSite" ON "Article"."ArtId"="ArticleSite"."ArtsPurch" WHERE  "Article"."ArtContext"=1 AND ("ArticleSite"."ArtsSitId"='63'

OR "ArticleSite"."ArtsSitId"='64') AND "Article"."ArtRecStatus">=0 ORDER BY "Article"."ArtId"

 

the link field artspurch is not the field I declared . It happens to be the first column of the table ArticleSite. This seems to be a bug. has anyone ever experienced anything like this?

 

( Fixed the formatting )

 

Message was edited by: Don Williams


Viewing all articles
Browse latest Browse all 3636

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>