Page 1 of 1

Error on a variable

Posted: Wed Nov 25, 2009 7:36 am
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..

Error on a variable

Posted: Wed Nov 25, 2009 1:08 pm
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'


Error on a variable

Posted: Thu Nov 26, 2009 12:35 am
by whythetorment
Thanx... The .ToString() seems to work...

Error on a variable

Posted: Thu Nov 26, 2009 2:14 am
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 ??

Error on a variable

Posted: Thu Nov 26, 2009 2:54 am
by Edward
Hi,

Please try to use the following expression:

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

Thank you.

Error on a variable

Posted: Thu Nov 26, 2009 3:01 am
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.

Error on a variable

Posted: Thu Nov 26, 2009 10:01 am
by Edward
Hi

Please check the ReadOnly checkbox and write the following expression:

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

Thank you.