Crystal Reports on the web

Looking at the huge number of links, my code snippets and samples that I've accumulated during my journey with Crystal Reports and Report Server (RAS), I've realized that something should be done with all that. So, for all who are struggling with similar problems I've faced while pursuing that elusive goal of putting Crystal Reports on the web, I will put as much information here as I can ...

Tuesday, June 15, 2004

How to find whether field exists in ResultFields collection

Finally...
Assume that we have fieldString already, and reportClientDocument object:
string fieldString;
ReportClientDocument _reportClientDocument;

// fieldString value will look like 'tablename.fieldname',
// so we should split it if we want just field name
char period = '.';
int periodIndex = fieldString.IndexOf(period);

string tableName = fieldString.Substring(1, periodIndex-1);
string fieldName = fieldString.Substring(periodIndex+1, fieldString.Length-(periodIndex+2));

int fldIndex = _reportClientDocument.DataDefinition.ResultFields.Find(fieldName, CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
if (fldIndex == -1)
{
// do something if not found
}
else
{
// do something if found... or do nothing...
}

If you want full qualified name, use crFieldDisplayNameLong instead of crFieldDisplayNameName, and full fieldString ...

0 Comments:

Post a Comment

<< Home