DateType that can be: True, False or Null?

  • Thread starter Thread starter DotNetNewbie
  • Start date Start date
D

DotNetNewbie

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;
 
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.
 
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
 
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.
 

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

Back
Top