Can a boolean data type be null?
I'm passing a parameter to a stored procedure. It's type is defined by the
line:
....
SqlParameter paramOK = cmd.Parameters.Add("@IsOK",
SqlDbType.Bit);
....
and it's value is set using:
....
paramIsOK.Value = null;
....
but it doesn't like this (I'd like to have the null possibility if a user
has neither replied Yes nor No to a question on a form.)
many thanks
Pete 6 10591
Italian Pete wrote: Can a boolean data type be null?
Not quite. I'm passing a parameter to a stored procedure. It's type is defined by the line: ... SqlParameter paramOK = cmd.Parameters.Add("@IsOK", SqlDbType.Bit); ...
and it's value is set using:
... paramIsOK.Value = null; ...
but it doesn't like this (I'd like to have the null possibility if a user has neither replied Yes nor No to a question on a form.)
C#'s 'null' is not the same thing as SQL's 'NULL'. The former is an
object reference to no object at all; the latter is a value of a
database field. You want
paramIsOK.Value = DBNull.Value;
--
Larry Lard
Replies to group please
Italian Pete wrote: Can a boolean data type be null?
Not quite. I'm passing a parameter to a stored procedure. It's type is defined by the line: ... SqlParameter paramOK = cmd.Parameters.Add("@IsOK", SqlDbType.Bit); ...
and it's value is set using:
... paramIsOK.Value = null; ...
but it doesn't like this (I'd like to have the null possibility if a user has neither replied Yes nor No to a question on a form.)
C#'s 'null' is not the same thing as SQL's 'NULL'. The former is an
object reference to no object at all; the latter is a value of a
database field. You want
paramIsOK.Value = DBNull.Value;
--
Larry Lard
Replies to group please
Hi,
"Italian Pete" <It*********@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com... Can a boolean data type be null?
In a DB yes , there is no bool in SQL server, there is BIT and yes, it can
accept nulls
I'm passing a parameter to a stored procedure. It's type is defined by the line: ... SqlParameter paramOK = cmd.Parameters.Add("@IsOK", SqlDbType.Bit); ...
and it's value is set using:
... paramIsOK.Value = null; ...
but it doesn't like this (I'd like to have the null possibility if a user has neither replied Yes nor No to a question on a form.)
Of course he does not like it, If you use DBNull.Value it will be pleased :)
For your case you could have a short int , with values 1, 2, 3 where each
one mean , yes, no , no answer
I alwasy try to avoid dealing with nulls :)
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Hi,
"Italian Pete" <It*********@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com... Can a boolean data type be null?
In a DB yes , there is no bool in SQL server, there is BIT and yes, it can
accept nulls
I'm passing a parameter to a stored procedure. It's type is defined by the line: ... SqlParameter paramOK = cmd.Parameters.Add("@IsOK", SqlDbType.Bit); ...
and it's value is set using:
... paramIsOK.Value = null; ...
but it doesn't like this (I'd like to have the null possibility if a user has neither replied Yes nor No to a question on a form.)
Of course he does not like it, If you use DBNull.Value it will be pleased :)
For your case you could have a short int , with values 1, 2, 3 where each
one mean , yes, no , no answer
I alwasy try to avoid dealing with nulls :)
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
By definition a bool must either be true or false. However, in version 2.0
of the .NET framework, MS will implement "nullable types." With this you
would, essentially, be able to declare a tri-state bool that can be either
true, false, or (I think) null. (If not null, then undefined). If you're
interested in more info on this check MS's web site. (Sorry I don't have the
correct link, but I'd start at "http://msdn.microsoft.com/vs2005".
..ARN.
"Italian Pete" wrote: Can a boolean data type be null?
I'm passing a parameter to a stored procedure. It's type is defined by the line: ... SqlParameter paramOK = cmd.Parameters.Add("@IsOK", SqlDbType.Bit); ...
and it's value is set using:
... paramIsOK.Value = null; ...
but it doesn't like this (I'd like to have the null possibility if a user has neither replied Yes nor No to a question on a form.)
many thanks
Pete
By definition a bool must either be true or false. However, in version 2.0
of the .NET framework, MS will implement "nullable types." With this you
would, essentially, be able to declare a tri-state bool that can be either
true, false, or (I think) null. (If not null, then undefined). If you're
interested in more info on this check MS's web site. (Sorry I don't have the
correct link, but I'd start at "http://msdn.microsoft.com/vs2005".
..ARN.
"Italian Pete" wrote: Can a boolean data type be null?
I'm passing a parameter to a stored procedure. It's type is defined by the line: ... SqlParameter paramOK = cmd.Parameters.Add("@IsOK", SqlDbType.Bit); ...
and it's value is set using:
... paramIsOK.Value = null; ...
but it doesn't like this (I'd like to have the null possibility if a user has neither replied Yes nor No to a question on a form.)
many thanks
Pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
by: FrancisC |
last post by:
how to define Boolean in C ?
boolean abc; ???
is it default as True or False??
|
by: G Dean Blake |
last post by:
I read in an earlier post that this would work:
If Not myrow.DeletedByUser Is DBNull.Value Then
But it gets a diagnostic if DeletedByUser is a boolean. How can I check to
see if a boolean is...
|
by: HS1 |
last post by:
Hello
Could you please help for a simple boolean expression
If a is not equal to Null
I tried
If (a != null) Then
|
by: Peter Kirk |
last post by:
Hi
is it it correct that variables of types like Boolean and Int32 cannot be
null?
It appears these types are structs, and not classes and therefore variables
cannot be assigned the value...
|
by: shawnk |
last post by:
Given several nullable boolean flags;
bool? l_flg_01 = true;
bool? l_flg_02 = false;
bool? l_flg_03 = true;
bool? l_result_flg = null;
I would have liked...
|
by: dba123 |
last post by:
Why am I getting this error for Budget?
Error: An exception of type 'System.FormatException' occurred in
mscorlib.dll but was not handled in user code
Additional information: String was not...
|
by: Malte |
last post by:
Hello there,
We got a problem atm with our 20k database. Everytime we search for sth. with double quotes it takes much more longer than without.
Here is what we did:
mysql> SELECT COUNT(*)...
|
by: Simon Brooke |
last post by:
The DOM API has included public Node importNode(Node,boolean) as a method
of the Document interface for a long time. Does anything actually
implement it? Xerces 2 is giving me:
...
|
by: =?iso-8859-2?Q?Marcin_Dzi=F3bek?= |
last post by:
Hi All:
I need to get (filter in) some dataview's rows with DBNULLs in column of boolean type:
Actually to get the only rows with DBNULL, I use code like this:
DV.RowFilter =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |