How to check that a column exists in a datasource

Stimulsoft Reports.WEB discussion
Post Reply
ewalcher
Posts: 14
Joined: Sun Apr 01, 2018 6:45 am

How to check that a column exists in a datasource

Post 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?
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

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

Post 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.
ewalcher
Posts: 14
Joined: Sun Apr 01, 2018 6:45 am

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

Post 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
Lech Kulikowski
Posts: 6252
Joined: Tue Mar 20, 2018 5:34 am

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

Post 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.
Attachments
Annotation 2019-03-21 190110.jpg
Annotation 2019-03-21 190110.jpg (170.43 KiB) Viewed 2057 times
Post Reply