473,385 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DateType that can be: True, False or Null?

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
6 2412
"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
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
????? = 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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: F. Da Costa | last post by:
Hi all, Following two sniperts of code I'm using and getting very interesting results from. ..html <tr id="1" class="segment" open="false"> This is the segment under 'investigation' ..js
7
by: Bill Reed via AccessMonster.com | last post by:
I have a field called "Wiring" in a query which is boolean. If I place "True Or False" in the criteria for the field, I get all records (there are no nulls in the recordset). Likewise if I place...
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
4
by: Wayne Wengert | last post by:
I am using VB in a VSNET 2003 Windows application. I've run into a situation where, when trying to set a bit value in a SQL Server 2000 database I get errors because the values extracted from a...
2
by: xllx.relient.xllx | last post by:
Hi, there. I need two simple things explained to me: 1.) I want to know why the "true" overloaded operator method gets called with a test to a null-initialized instance: public class...
30
by: Jason | last post by:
I am fairly new to ASP--I have been using it about 2 months. I did these tests (below), and it doesn't make sense to me. False is equal to 0, and that's fine. True should be equal to 1, but it's...
1
by: JWest46088 | last post by:
I'm getting this error when I try to preview my code: TypeError: Error #1009: Cannot access a property or method of a null object reference. at therun4life_fla::MainTimeline/frame1() I don't...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.