Click here to Skip to main content
15,902,635 members
Articles / Programming Languages / Visual Basic
Article

Function for clear null and set default value in DataTable

Rate me:
Please Sign up or sign in to vote.
2.11/5 (9 votes)
25 Aug 20051 min read 53.1K   618   19   1
Function for clear null and set default value in DataTable
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


Written By
Web Developer
Thailand Thailand
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
NewsThanks! DateTimepicker work normally! Pin
svb55511-May-06 8:40
svb55511-May-06 8:40 

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

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