Click here to Skip to main content
Licence 
First Posted 25 Aug 2005
Views 38,000
Bookmarked 19 times

Function for clear null and set default value in DataTable

By | 25 Aug 2005 | Article
Function for clear null and set default value in DataTable
 
Part of The SQL Zone sponsored by
See Also
Title:       Function for clear null and set default value in Data Table
Author:      Pakorn Indhatep
Email:       pakorncs@bizslash.com
Environment: Visual Baic.NET
Keywords:    ADO.NET, DataTable, Data Table, Null, Default
Description: Function for clear null and set default value in Data Table
Section      VB.NET
SubSection   Data Access

Introduction

I use both Delphi and Visual Baic.NET for my projects. I like some data access method in Delphi. Look back to our .NET, when we get data from database. We will get some spaces from 'char' data type in database. And we will get null value from null data in database too. Who's care? everybody know that. But Delphi has data access that get rid of those problem. They use something like RecordSet.FieldByName('FirstName').AsString. The value from this method is interesting. Null will be '' (zero ascii code char) and spaces that follow 'char' data type will be trim. It is easy to manage data in our program.

Using the code

It is easy. We just use this function follow data retrieving process. It doesn't use like Delphi, that It is method in data object. It is just a function, but it is useful and work! For example ...

  '--- dbDS is DataSet ---
  gloDBAdap.Fill(dbDS, "T_Customer")
  SetDefaultClearNull(dbDS.Tables("T_Customer"))

How is it work?

It don't have anything more than iteration and examine.
1.1 Iterate the DataColumn Objects in DataTable.
1.2 Examine data columns for each data type and set default value.

2.1 Iterate the DataRow Objects in DataTable.
2.2 Iterate the DataColumn Objects in DataTable.
2.3 Examine data columns for each data type , look through in each item
     and set value if it is null value. If it is string column, trim it too.

History

-

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Pakorn Indhatep

Web Developer

Thailand Thailand

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
NewsThanks! DateTimepicker work normally! Pinmembersvb5558:40 11 May '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 26 Aug 2005
Article Copyright 2005 by Pakorn Indhatep
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid