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 10592
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |