469,604 Members | 2,358 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,604 developers. It's quick & easy.

DataView.RowFilter IsNull: DBNull in column of boolean datatype

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 = "(IsNull(MyBooleanColumnName, True) = True) AND (IsNull(MyBooleanColumnName, False) = False)"

or ex.
DV.RowFilter = "(IsNull(MyIntegerColumnName, 1) = 1) AND (IsNull(MyIntegerColumnName, 0) = 0)"
for columns of Integer...

I know - looks strange, but it seems to work.
However I'm not sure if it's correct...

Is there any better way to get only dbnulls from boolean column?

Thanks
Marcin Dzióbek

Jun 27 '08 #1
6 16837
Your method seems OK except if you are trying to fix a data table on a
server DB where a boolean column contains null values -- I would fix
that at the server - set a default value of 0 for false and everywhere
that is null -- set to false. Then make that boolean column to not
allow null values (will be a bit column).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #2
Hi Rich:

Thaks for replay:
.... except if you are trying to fix a data table on a
server DB where a boolean column contains null values -- I would fix
that at the server - set a default value of 0 for false and everywhere
that is null -- set to false. Then make that boolean column to not
allow null values (will be a bit column).
1. I can't use RDBMS to "fix" table... I'm just trying to develop user control: another custom datagridview with
filter's tools.
It has a property - datasource - where the consumer will assign reference to "his own" datatable. What if consumer will
use ReadXml to create dataset and datatable?

2. IMHO: table "where a boolean column contains null values" is OK - I wouldn't change that. If we eliminated null
values by changing table/database project in RDBMS, we still cannot avoid null values in System.Data.DataTable object.
I'm not sure even if datadapter.fill method sets DataColumn.AllowDBNull and DataColumn.DefaultValue properties; it may
depend MissingSchemaAction property and kind of RDBMS... but ofcourse I may be wrong.

--
Marcin Dzióbek

Jun 27 '08 #3
Hello again,

my explanation pertains primarily to MS Sql Server. I am fairly certain
that if a table on the backend DB contains a bit column to be used as a
boolean column -- it would be counter intuitive to have 3 values -
True/Null/False. The field should either be true or false if it is a
boolean column. Thus, if your project is using this column as a boolean
and the Null value cannot be eliminated - then the suggestion that I
offer is that I wish you well. My question is this: why compensate for
something down the road instead of fixing it at the source?

IF there is no possibility of fixing your problem at the source, then it
appears that the method you are asking about is the only way for you to
continue with your project.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #4
Marcin Dzióbek wrote:
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 = "(IsNull(MyBooleanColumnName, True) = True) AND
(IsNull(MyBooleanColumnName, False) = False)"
or ex.
DV.RowFilter = "(IsNull(MyIntegerColumnName, 1) = 1) AND
(IsNull(MyIntegerColumnName, 0) = 0)" for columns of Integer...

I know - looks strange, but it seems to work.
However I'm not sure if it's correct...

Is there any better way to get only dbnulls from boolean column?
It is so simple, you will kick yourself:

DV.RowFilter = "MyColumnName Is Null"
Jun 27 '08 #5
Hi Steve:
It is so simple, you will kick yourself:

DV.RowFilter = "MyColumnName Is Null"
You're absolutely right! How could I live without that...
Now I kick myself :)

THANKS!

--
Marcin Dzióbek

Jun 27 '08 #6
>... My question is this: why compensate for
something down the road instead of fixing it at the source?
IMHO there is nothing to fix. I just don't agree that null values are wrong.
IF there is no possibility of fixing your problem at the source, then it
appears that the method you are asking about is the only way for you to
continue with your project.
Steve opened my eyes... there is better method (should be mentioned in MSDN DataView.RowFilter's help page).

Thanks
--
Marcin Dzióbek

Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by KC | last post: by
1 post views Thread by Engineerik | last post: by
3 posts views Thread by randy1200 | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.