Page 1 of 1

How to check that a column exists in a datasource

Posted: Thu Mar 21, 2019 4:02 am
by ewalcher
Hi, I have a variable in a report that references a column in a data source. My issue is that the column might not be present in the data source in which case there will be an error when rendering the report.

Is there a way to check that a column exists in a data source using an expression?

Re: How to check that a column exists in a datasource

Posted: Thu Mar 21, 2019 11:04 am
by HighAley
Hello.

What type of data source do you use?
Maybe it's better to check your data?
The variable should be used in the report.
What value should it have?
What should be with this variable when there is no data?

Thank you.

Re: How to check that a column exists in a datasource

Posted: Thu Mar 21, 2019 2:26 pm
by ewalcher
Hi, the data source is a SQL view of a few tables that might have columns depending on some configuration.

e.g. SourceView
col1 int
col2 string
col3 bool

I need to check first that col3 exists before using it in a variable.

For example, I might have an expression in a report: {col3 ? "Write something" : "Write something else"}
If col3 doesn't exist in the Source I will get an error.
How do I check that col3 exist? If it doesn't I'm hoping to output a blank string

Re: How to check that a column exists in a datasource

Posted: Thu Mar 21, 2019 6:02 pm
by Lech Kulikowski
Hello,

You can use the following expression:
(Categories.DataTable.Columns.Contains("CategoryColumn") ? Categories.CategoryID.ToString() : "----")

But it will work only in NET based products.

Thank you.