Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Problem with null values

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-01-13 : 11:30:58
I have imported a large Access table into SQL Server. One of the fields is a bit field, but the Access table has a large number of nulls in this field so when I try to display the data in bound text boxes on my web page I am getting the error 'Cast from type 'DBNull' to type 'Boolean' is not valid for those records with null and not 1

How can I get round this other than running an update query on my sql table to replace the nulls with 0

I am using asp.net

jhermiz

3564 Posts

Posted - 2005-01-13 : 11:31:57
quote:
Originally posted by Pinto

I have imported a large Access table into SQL Server. One of the fields is a bit field, but the Access table has a large number of nulls in this field so when I try to display the data in bound text boxes on my web page I am getting the error 'Cast from type 'DBNull' to type 'Boolean' is not valid for those records with null and not 1

How can I get round this other than running an update query on my sql table to replace the nulls with 0

I am using asp.net




just write code to check if it is null ?

And handle the result appropriately...


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]


Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-01-14 : 09:58:53
I fill a dataset and my textboxes are bound so they automatically fill. How do I then code to cope with the null ?
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2005-01-14 : 10:36:34
You can check to see if something is null by doing something like this.

I'm guessing your using VB.NET

If Convert.IsDbNull = record("Your Boolean Column") Then
Use a value of 0
Else
Use value from your record

Dustin Michaels
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-14 : 12:42:37
or if you can live with it then do in your sql

select coalesce(col1, '') ...
from ...

Go with the flow & have fun! Else fight the flow
Go to Top of Page

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2005-01-14 : 14:28:52
Or use a SP and isnull to build your page.

Select Isnull(yourcolumn,0)
from yourtable

Jim
Users <> Logic
Go to Top of Page
   

- Advertisement -