473,398 Members | 2,088 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,398 software developers and data experts.

SQLServer IsNull() & DataReader

I'm trying to keep the logic of my web pages to a minimum. One of the
problems I face regularly is dealing with DBNull's. I know how to code my
way out of them, but I thought perhaps it'd be easier to take care of it at
the database level, rather than the asp.net level.

The SQL Server function IsNull() would seem to do the trick. But I'm having
problems. If, for example, I use this SQL statement ...

Dim strSQL as String = "SELECT IsNull(myDate,'1/1/1900') as
myDateCol from myTable;"

.... execute it properly (using a SQLDataReader) against the database, and
then refer to it in my <asp:repeater> as ...
<%# Container.DataItem("myDateCol")%>

.... I'll get the error that the index is out of range (or some such error),
indicating that the SQL statement isn't producing such a column. Remove the
IsNull() function, reference the column in the <asp:repeater> instead as
"myDate", and all works again.

Any ideas how to make this work?

Thanks for any help!

--Brent
Nov 18 '05 #1
1 2194
It depends on what you are doing. For pure display, you can run some SQL
like the following:

SELECT CASE WHEN myDate IS NULL THEN ''
ELSE CAST(myDate AS VARCHAR(11)) END AS myDateCol -- Everything becomes
a character, not a date
FROM myTable

This is problematic if you are using UPDATES and INSERTS, however.

With Strongly Typed DataSets, you have a bit more control, although you
still have to worry about the test for NULL on output.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Brent" <bbigler @ ahem-'whoopee' . com> wrote in message
news:5m*****************@newssvr27.news.prodigy.co m...
I'm trying to keep the logic of my web pages to a minimum. One of the
problems I face regularly is dealing with DBNull's. I know how to code my
way out of them, but I thought perhaps it'd be easier to take care of it at the database level, rather than the asp.net level.

The SQL Server function IsNull() would seem to do the trick. But I'm having problems. If, for example, I use this SQL statement ...

Dim strSQL as String = "SELECT IsNull(myDate,'1/1/1900') as
myDateCol from myTable;"

... execute it properly (using a SQLDataReader) against the database, and
then refer to it in my <asp:repeater> as ...
<%# Container.DataItem("myDateCol")%>

... I'll get the error that the index is out of range (or some such error), indicating that the SQL statement isn't producing such a column. Remove the IsNull() function, reference the column in the <asp:repeater> instead as
"myDate", and all works again.

Any ideas how to make this work?

Thanks for any help!

--Brent

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: YURYSSG | last post by:
I migrated a DB from Access 2000 to SQLserver 2000. The tables are OK, but I see the old Access views... as TABLE in SQLserver!! Any suggestions? --
2
by: Mark | last post by:
I am trying to retrieve the content of a text column in SqlServer using a DataReader. When I ask for the data, using either GetString () or GetSqlString (), the data gets truncated all ellipses...
0
by: how can i insert a image to SQLServer? | last post by:
I want to insert some strings and images which from richTextBox into SQLServer. I could insert it into SQLServer,such as follows: FileStream s=new FileStream...
14
by: Roy Gourgi | last post by:
Hi, I need to store and retrieve information from a database. It looks as though there is a lot more support for SQLServer than there is for Access, correct me if I am wrong. What do I have...
4
by: Mike | last post by:
Hello, How can I get Random data from Dataset or datareader THanks -- Regads, Rochdi
0
by: Ron | last post by:
Hi there My company is developing a web based document archival and retrieval system, using ASP.NET, c# and sqlserver 2000. This development is in testing at present and all looks promising. ...
0
by: selvakishore | last post by:
Hai, I have a pblm when creating a view which has a self join column named exportquantity. It takes much time to load. How can i reduce the loading time of that view. Pls help. CREATE ...
0
by: Rob | last post by:
I have a Webservice written in C# that provides data to both a web browser through ASP.net and to a VC++ client. I have been able to retrieve data from SQLServer and passing to my C++ client as...
5
by: bobh | last post by:
Hi All, I have this query which updates a field based on the result of an IIF statement. The table is on SQLServer and I'm linked to it and it has many records and will take Access a very long...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...

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.