IIF Statement in Access is cutting off my string in c#

D

Dave

I have a field with data type of memo in my access database. I run a
query from c# to access this field and it cuts off my string to only
255 characters. If i run this query directly in access it works fine.
If i run this query without the iif statement it works fine. It only
cuts off my string when i run this query in c# WITH the iif statement.
Here is the statement that doesn't work.

SELECT
IIF(ISNULL(t1.field1), t2.field1, t1.field1) AS desc
FROM
table1 t1 LEFT JOIN t2 ON t1.field2 = t2.field2

If you run this in access it works. If you change it to:

SELECT
t1.field1
FROM
table1 t1

it works fine.

It just doesn't work in c#. Can anyone help
 
S

scott blood

Dave,

I think this is something to do with the datatypes.

When you run a query i.e. Select text_field_1 from MyTable, you are directly
accessing that field, thus returning the type as well.

However using compound statements or functions inside the query, afaik, you
are not directly accessing that field, you are actually accessing the return
result from the function.

Have you tried creating and calling a query from within access rather than
accessing the table directly?

Regards
Scott Blood
C# Developer
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Dave said:
I have a field with data type of memo in my access database. I run a
query from c# to access this field and it cuts off my string to only
255 characters. If i run this query directly in access it works fine.
If i run this query without the iif statement it works fine. It only
cuts off my string when i run this query in c# WITH the iif statement.
Here is the statement that doesn't work.

Can you post the code ni question? a String in C# is not limited to 255
chars , and I believe Access does not impose that limit iehter
 
B

Ben Voigt

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,



Can you post the code ni question? a String in C# is not limited to 255
chars , and I believe Access does not impose that limit iehter

Access Text is <= 255 characters
Memo allows storing larger amounts of text.

Are t1.field1 and t2.field1 both Memo, or is one Text and one Memo?
 
S

scott blood

Hello,

I have investigated this further and it seems that the IIF statement cannot
return an object or binary type field such as a memo field, thus converting
it back to a Text type field.

Regards
Scott Blood
C# Developer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top