Use of Null keyword in CommandText

  • Thread starter Thread starter Camel
  • Start date Start date
C

Camel

Hi,

I have the following SQL code :

SELECT null AS Fred from Debtors

This is part of the SelectCommand.CommandText for an OleDbAdapter (Jet
4). When I test this SQL within Visual Studio I get a binary value,
not a blank field.

I also get the following error when the SQL is parsed :

Error in SELECT clause: expression near 'NULL'.
Unable to parse query text.

Does anyone have any ideas?

Regards,

Camel
 
Null is a reserved word and in the context of your query, they processing
engine thinks it's a column name. If you want null values to come in as
'FRED' Then use ISNULL(SomeColumn, Fred). Otherwise, change the column name
from Null to something like _null. As a rule, and I don't mean to preach,
using Reserved words for field names probably isn't a habit worth keeping.

HTH,

Bill
 
Hmm. I'm using the reserved word in its context, not as a field name -
that's what the Fred part is for. I want Fred to be Null for all
records. Perhaps if I use a literal value as a substituted example you
might see what I mean :

SELECT 'Some Result' AS Fred FROM Debtors

Anyway, back to my original question. It appears that Null *is*
interpreted as a binary value (I put the Null declaration in my Access
backend - still same result). Essentially, I want null to be
interpreted as DBNull when my object is assigned a value - what am I
doing wrong?

Regards,

Camel
 
Hi,

I think the SQL syntax is completely right and executable. Actually it
must be VS.NET's SQL designer that misunderstands. You can just ignore
it and run program. It should work fine.

Ruxo

(e-mail address removed) (Camel) wrote in
 
I agree. But when my adapter fills the dataset, I get the following
error :

Inconvertable type mismatch between SourceColumn 'InvoiceCancelled' of
Byte[] and the DataColumn 'InvoiceCancelled' of DateTime.

Which leads me back to the thing where Null is interpreted as a binary
value not DBNull. Any clues?

Regards,

Camel
 
Back
Top