By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,983 Members | 2,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,983 IT Pros & Developers. It's quick & easy.

DateType that can be: True, False or Null?

P: n/a
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;

Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"DotNetNewbie" <sn***********@yahoo.comwrote:
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.
Jun 27 '08 #2

P: n/a
On Thu, 15 May 2008 13:01:57 -0700 (PDT), DotNetNewbie
<sn***********@yahoo.comwrote:
>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.

Jun 27 '08 #3

P: n/a
????? = DBNull.Value

Does that work?

On May 15, 1:01 pm, DotNetNewbie <snowman908...@yahoo.comwrote:
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;
Jun 27 '08 #4

P: n/a
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

<snowman908...@yahoo.comwrote:
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.
Jun 27 '08 #5

P: n/a
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
Jun 27 '08 #6

P: n/a
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-
europe.comwrote:
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
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.