Groups > Databases > Access Databases and AccessDataSource Control > Re: IIF or CASE WHEN function




IIF or CASE WHEN function

IIF or CASE WHEN function
Mon, 31 Mar 2008 12:14:57 +000
Hi

I'm connecting to an MS ACCESS database table call Answers. I want to make a
gridview where one of the columns will state if the user answered a question
correctly or not. In the MS ACCESS data source I'm trying to get the IIF
function to return either 'correct' or 'incorrect' by comparing the
CorrectAnswer field to the SuppliedAnswer, like so:
IIF(CorrectAnswer=SuppliedAnswer, 'Correct','Incorrect'). However the query
builder in VWD changes the syntax to IIF('CorrectAnswer=SuppliedAnswer',
'Correct','Incorrect') which always returns 'Correct' which is wrong. If I put
the field name between [] the same thing happens.

I have also tried the following: CASE WHEN SuppliedAnswer = CorrectAnswer THEN
'Correct' ELSE 'Incorrect' END but when I execute the query it get an
iErrorInfo.GetDescription Failed with E_Fail(0x80004005)

Please help

 

Thanks

David
Post Reply
Re: IIF or CASE WHEN function
Mon, 31 Mar 2008 13:43:08 +000
Don't work in Access much, so this is a guess.

After the CASE statement, did you provide an alias for that value?  Because if
you did not, that might be the reason the GetDescription didn't work.
Post Reply
Re: IIF or CASE WHEN function
Mon, 31 Mar 2008 14:06:57 +000
Sorry, the full case statment goes: CASE WHEN SuppliedAnswer = CorrectAnswer
THEN 'Correct' ELSE 'Incorrect' END As EXPR1
Post Reply
Re: IIF or CASE WHEN function
Mon, 31 Mar 2008 16:40:22 +000
You could try creating the IIF query within Access, then save it with a
meaningful name.  Then call it as if it were a stored proc in SQL Server.
(Command.CommandType = CommandType.StoredProcedure).  Case is not supported by
Access/Jet. The VWD query builder is not very good with Access.
Post Reply
Re: IIF or CASE WHEN function
Tue, 1 Apr 2008 09:19:28 +0000
Thanks for that. Do you perhaps have a VB example of how to do that. Currently
I'm just dragging MS Access data connections onto the form and not really
working the connections in code - which I would prefer to do
Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact