Error on a variable

Stimulsoft Reports.NET discussion
Post Reply
whythetorment
Posts: 20
Joined: Fri Nov 20, 2009 7:40 am

Error on a variable

Post by whythetorment »

Hi,

I have a variable, and then the following code :

Code: Select all

IIF(DataSource1.DrvLicEndorsed=="1","Yes","No")
In my database DrvLicEndorsed is an integer.

But when I try to run the report in the designer, I keep getting Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists.

I've tried the following variations, and none works

Code: Select all

IIF(DataSource1.DrvLicEndorsed=="1","Yes","No")
IIF(DataSource1.DrvLicEndorsed==1,"Yes","No")
IIF(DataSource1.DrvLicEndorsed="1","Yes","No")
IIF(DataSource1.DrvLicEndorsed=1,"Yes","No")
{IIF(DataSource1.DrvLicEndorsed=="1","Yes","No")}
{IIF(DataSource1.DrvLicEndorsed==1,"Yes","No")}
{IIF(DataSource1.DrvLicEndorsed="1","Yes","No")}
{IIF(DataSource1.DrvLicEndorsed=1,"Yes","No")}
On a different report, I have the exact same thing, but then I just have it on a normal textfield, but then there is no problem.
{IIF(DataSource1.Pnt1=="1","Yes"," ")}

Pnt1 is also an integer on my other report..
Brendan
Posts: 309
Joined: Sun Jul 16, 2006 12:42 pm
Location: Ireland

Error on a variable

Post by Brendan »

The IIF statement returns your data as an object so you set the true/false values to strings of "Yes" and "No", they will be returned as objects rather than strings.
You can convert them back to a string if needed

Code: Select all

IIF(DataSource1.DrvLicEndorsed==1,"Yes","No").ToString()
There may be other ways to achieve what you want also depending on what you are trying to do.
Text Formatting allows you to format a value with a boolean style. you can specify a value for 'Yes' and a value for 'No'

whythetorment
Posts: 20
Joined: Fri Nov 20, 2009 7:40 am

Error on a variable

Post by whythetorment »

Thanx... The .ToString() seems to work...
whythetorment
Posts: 20
Joined: Fri Nov 20, 2009 7:40 am

Error on a variable

Post by whythetorment »

New problem now, I have this now : IIF(DataSource1.NoPassengers == 1,"No","Yes").ToString()

In my db NoPassengers is an int, and the value is a 1 of the record im returning, but on my report it is showing "Yes". Its suppose to show "No" ??

Then I will have something like IIF(DataSource1.DrivAlcTest == "1", "Yes", "No").ToString() where DrvAlcTest is an varchar(1), and the value in the is a 0, so it's returning "No" which is correct...

Also, I have another one IIF(DataSource1.VehMove == "1", "Yes", "No").ToString() where VehMove is also a varchar(1), and in the db the value 1, but it is returning a "No". It should be yes...

Am I missing something here ??
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Error on a variable

Post by Edward »

Hi,

Please try to use the following expression:

{IIF(DataSource1.DrivAlcTest.ToString() == "1", "Yes", "No")}

Thank you.
whythetorment
Posts: 20
Joined: Fri Nov 20, 2009 7:40 am

Error on a variable

Post by whythetorment »

{IIF(DataSource1.DrivAlcTest.ToString() == "1", "Yes", "No")}
There is nothing wrong with the DrivAlcTest one... The NoPassengers and VehMove is wrong...

Tried this on vehmove : {IIF(DataSource1.VehMove.ToString() == "1", "Yes", "No")}

AND got the error : Invalid expression term '{'

This is on a variable, not in a normal textfield
Name: _VehMovable
Alias : _VehMovable
Type : string
Default Value : {IIF(DataSource1.VehMove.ToString() == "1", "Yes", "No")}

Readonly : Unchecked
Function : Checked.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Error on a variable

Post by Edward »

Hi

Please check the ReadOnly checkbox and write the following expression:

ToString(IIF(DataSource1.VehMove.ToString() == "1", "Yes", "No"))

Thank you.
Post Reply