Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DateType that can be: True, False or Null?

1 view
Skip to first unread message

DotNetNewbie

unread,
May 15, 2008, 4:01:57 PM5/15/08
to
Hi,

I need a datatype (or enum?) that can hold the possible values: true/
false/null

I will use it in ADO.NET code like:

sqlCmd.Parameters.Add("@isApproved", SqlDbType.Bit, 1).Value = ?????;

This way I can pass values of true,false or null to my stored
procedure.

Is there a way to do this or do I have to do things like :

if(myEnum != MyEnum.NULL)
sqlCmd.Parameters.Add("@isApproved", SqlDbType.Bit, 1).Value =
myEnum;

Paul E Collins

unread,
May 15, 2008, 4:57:00 PM5/15/08
to
"DotNetNewbie" <snowma...@yahoo.com> wrote:

> I need a datatype (or enum?) that can hold the possible values:
> true/false/null
> I will use it in ADO.NET code like:
> sqlCmd.Parameters.Add("@isApproved", SqlDbType.Bit, 1).Value = ?????;
> This way I can pass values of true,false or null to my stored
> procedure.

I think you should be able to use SqlBoolean from System.Data.SqlTypes.

Eq.


Gilles Kohl [MVP]

unread,
May 15, 2008, 4:57:50 PM5/15/08
to
On Thu, 15 May 2008 13:01:57 -0700 (PDT), DotNetNewbie
<snowma...@yahoo.com> wrote:

>Hi,
>
>I need a datatype (or enum?) that can hold the possible values: true/
>false/null

Nullable types may be just what you're looking for:

http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx

Regards,
Gilles.

Kalpesh

unread,
May 15, 2008, 5:24:46 PM5/15/08
to
????? = DBNull.Value

Does that work?

qglyir...@mailinator.com

unread,
May 15, 2008, 6:27:00 PM5/15/08
to
Hi Gilles,

Ok, I confess, I am too lazy to try so I will ask… would this work
even if the sql parameter requires DBNull.Value?

Is passing null to an sql parameter equivalent to passing
DBNull.Value?

Thanks.

On May 15, 3:57 pm, "Gilles Kohl [MVP]" <no_email_available@> wrote:
> On Thu, 15 May 2008 13:01:57 -0700 (PDT), DotNetNewbie
>

Joachim Van den Bogaert

unread,
May 16, 2008, 3:39:45 AM5/16/08
to
With NUnit referenced, try this to find out whether DBNull and null
are the same (you will find they are not):

[TestFixture]
public class Test
{
[Test]
public void NullDBNullEqual()
{
Assert.AreEqual(null, DBNull.Value);
}
}

Joachim

qglyir...@mailinator.com

unread,
May 16, 2008, 9:28:16 AM5/16/08
to
Thanks Joachim

I realize that DBNull.Value and null are not equal, that wasn’t the
question.

What I was interested in knowing is if the Value property of the SQL
parameter (SqlParameter) object will internally treat DBNull.Value and
null as being the same thing.

This is really no big deal, I was just curious.


On May 16, 2:39 am, Joachim Van den Bogaert <joac...@yamagata-

0 new messages