Recent Articles

MySQL FULLTEXT Indexing & Searching
MySQL has supported FULLTEXT indexes since version 3.23.23. VARCHAR and TEXT Columns that have been indexed with FULLTEXT can be used with special SQL statements that perform the full text search in...

Installing A MySQL Database Using A MySQL...
Whenever you purchase or acquire a MySQL database (such as from a website like WebContents.org), chances are it will come as a MySQL injection script. An injection script is simply a SQL script that, when executed...

MySQL IPO, Oracle Unbreakable Support For MySQL?
Matt Aslett writes that Oracle may be considering Unbreakable Support for MySQL and that MySQL Co. is likely to IPO later this year. When MySQL files for...

Convert A MySQL Injection Script For Use In Microsoft...
MySQL Server is the most widely used database management system in the world, primarily because it is open source and free. Hence, most databases you...

Developing Countries Breeding Grounds...
Red Herring's Falguni Bhuta predicts "More (Open Source) momentum in developing countries": "Open-source software's transparent nature and low-cost will make it more popular among developing countries such...

SQL Server Triggers
Triggers are stored procedures which are fired when data is modified in an underlying table. They can evaluate data being added to a table for validation purposes..

SQL Server 2000 Data Types
SQL Server requires that each variable and column in a table should be defined with respect to the type of data it will store. From a bit to a huge image and binary storage types, the allocation is supposed to help the...

Using DataTables More For Improving Performance
There are some features in the System.Data.DataTable class that a lot of developers don't utilize. I base that statement on different code samples I've seen on blogs and article bases during the last couple of years.


03.27.07


Removing Nulls From A DataTable

By Mads Kristensen

The individual cells in a DataTable can have a null value in the form of System.DbNull.Value.

If the DataTable is created by querying a database through ADO.NET, you can write the SQL statement in a way eliminates nulls. It could look like this "SELECT isnull(name, 'n/a') AS name FROM products".

However, there can be scenarios where you don't have the chance to manipulate the DataTable before you use it.

Such a scenario have I recently been involved in and the problem was that the data retrieved from a database could contain nulls in any of the integer type columns.

If I then bind the DataTable to a GridView in ASP.NET, I had to do a lot of workarounds to calculate footers and other values based on those columns.

Instead of doing the workarounds in a lot of different places in the code, I decided it was a better idea to clean the DataTable for nulls before it is used.

Low Rate eCommerce & Retail Plans

That led to the CleanDataTable method below, that replaces null values with zeros for a few integer type columns.



The point is that you only have to clean it ones and avoid any workaround for handling null values.

Comments


About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/


About SQLproNews
SQLproNews is a collection of up to date tutorials and insightful articles designed to help SQL users of any skill level implement successful SQL systems and practices. SQL Strategies and Tactics for Business

SQLproNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
SQLproNews.com WirelessProNews.com
CProgrammingTrends.com SysAdminNews.com




-- SQLProNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2007 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

advertising info | news headlines | free newsletters | comments/feedback | submit article


SQL Strategies and Tactics for Business SQLproNews News Archives About Us Feedback SQLproNews Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact