Function for clear null and set default value in DataTable






2.11/5 (9 votes)
Aug 26, 2005
1 min read

53142

618
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
-