/// Frank Hagen: Professional Web Developer, C# User, Reformed Über-geek RSS 2.0
# Tuesday, October 16, 2007

I shouldn't be surprised, but I am:  A customer complained to me that the Flag field they wanted to indicate a Yes or No value was failing.  The Yes value was working fine, but No was being returned when they hadn't set anything yet.

I didn't realize that booleans were meant to represent Yes, No, and Maybe.  Silly Programmer, no bits for you.

Tuesday, October 16, 2007 10:43:53 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
Worse Than Failure
# Tuesday, October 09, 2007

I am struggling with issues posting code samples in WordPress.  I am painfully aware that much of my code is cut off visually on the main page, and highlighting is spotty at best.  Suggestions for making it work in WordPress are appreciated.  I'd love to add an external stylesheet, but am loathe to pay for that add on.  An "extra" to handle it would be great, as long as it doesn't violate any EULAs.

Of course, WP layouts are pretty lacking too, without purchasing additional capabilities.  If I wanted to spend money doing this, I'd host this blog myself somewhere else and have Ultimate Freedom

I am working on it....

Update [10.08]:  I will be looking at Blogger and Blogsome to evaluate their engines for free coding blogs.  It is possible I may move again.  Also, I will renew my feedburner account so moves are more transparent; or completely so for RSS readers.

Tuesday, October 09, 2007 9:44:55 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
Blog

This really should have been more obvious to me, so why did I have to look it up?  If you need to check for NULL in a returned field from SQL (or any other datasource), you should the .Equals method on System.DBNull.Value.  I usually prefer the "==" notation for conditionals, but that's just me.  This is more efficient.  The code follows:

if (!dsSpecQuery.Tables[0].Rows[0]["device_type_end"].Equals(System.DBNull.Value)) 
{
    _EndDate = Convert.ToDateTime(dsSpecQuery.Tables[0].Rows[0]["device_type_end"]);
}

Of course, dsSpecQuery is a DataSet, and the field in question is DateTime out of SQLServer (not that it matters for the conditional).

Tuesday, October 09, 2007 9:38:06 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
.NET | Programming | SQL
# Thursday, October 04, 2007

Lord Foul's Bane is a fantasy classic that I have read before; twice, I believe. But it was so long ago, that I have been meaning to re-read it for awhile.  The books I have are so old, Amazon doesn't even have the images to link in.  Hopefully Wikipedia doesn't mind.

Lord Foul's Bane is the beginning of the story of Thomas Covenant called Unbeliever.  He is a modern day man afflicted by Leprosy.  He finds himself unwillingly thrust into The Land, a mystical realm that is able to resolve some of his nerve damage and remove his disease.  But he is wary, knowing it must be too good to be true.  He must deliver a message of Doom to the leaders of the Land, and resolve his inner turmoil of even being there.

Covenant is a reluctant hero with fears and flaws that match our own.  Donaldson's treatment of him is very deep and extremely satisfying when looking for a character that is more realistically complex.  He spends much of this book battling the psyche of the main character himself.  There are others, I am certain, that have written this series up far better than I.  For more, find such a review online.  This is the first book of the first trilogy of the Chronicles of the Unbeliever.  The 2 trilogies were so popular that Donaldson has started the 3rd and final a couple years ago.  The Chronicles of Thomas Covenant are, without a doubt, required reading for any fantasy fan.

Thursday, October 04, 2007 1:23:00 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
Books
# Friday, September 21, 2007

Sometimes its necessary to script out data manipulation for deployments or automation.  The easiest vehicle in Windows is Windows Script Host (WSH) using VBScript.  Below is a very basic framework for accessing a database (MSSql) and looping a RecordSet.

''===// Retrieve Data from Database //=====
Const DBSERVER = "SQLDEV01"
Const DATABASE = "Cellular"
Const DBUSERID = "app_user"
Const DBPASSWD = "app_pass"

'' Construct ConnectionString
szADOConn = "Provider=SQLOLEDB;Network Library=DBMSSOCN;Persist Security Info=True;" &_ 
            "Data Source=" & DBSERVER & ";" &_
            "DATABASE=" & DATABASE & ";" &_
            "User ID=" & DBUSERID & ";Password=" & DBPASSWD & ";" 

Set DBConn = CreateObject("ADODB.Connection")
    DBConn.open szADOConn        
    szSqlQuery = "SELECT PhoneID, Field2, etc  FROM Import_Name WHERE PhoneID <= 200"
Set cmd = CreateObject("ADOdb.Command")
    cmd.CommandType = &H0001  ''adCmdText
    cmd.ActiveConnection = DBConn
    cmd.CommandText = szSqlQuery
Set RecordSet = CreateObject("ADODB.Recordset")
Set RecordSet = cmd.Execute(szSQLlc)

Do While Not RecordSet.EOF
  WScript.Echo RecordSet("PhoneID")  
  RecordSet.movenext
Loop

Set RecordSet = Nothing
Set cmd = Nothing
    DBConn.close
Set DBConn = Nothing

Of Course, it's possible to distill this down further, but I didn't for clarity (Consts) and it's better to not use implicit command objects by opening the database directly with the Recordset object.

Friday, September 21, 2007 10:08:01 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
SQL
# Thursday, August 30, 2007

When I am Emperor, I will have a quiet policy to fire any IT worker who starts an office lottery pool.  Not only are they wasting the time of people that are trying to get good work done, but they obviously do not have the mathematical and statistical skills to properly perform a programming or development task correctly.

What they do on their own time is, of course, their own business.  I love those who contribute to Ignorance Taxes.

Thursday, August 30, 2007 10:01:10 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
Rant
# Monday, August 20, 2007

Last week, I posted an entry about a simple call to an MS-SQL database with a warning that it should only ever be used in a quick and dirty scenario.  By that I mean when it doesn't make sense to integrate or create a Data Access Layer or class to do the heavy lifting for you.

The advantages of creating classes to do the data calls behind the scenes are many, not the least of which is easier development in the long run.  Take a look at the following code:

    Query qEmplQuery = new Query(); 
    qEmplQuery.ConnectionSettings = ConfigurationManager.ConnectionStrings["EmployeeDB"]; 
    qEmplQuery.StoredProcedure = "DW.PKG_HRPORTAL.PRC_EmployeeInfo"; 
    qEmplQuery.AddParameter("P_EmployeeNumber", szEmplNum); 
    qEmplQuery.MinutesCached = 12 * 60; 
    DataSet dsEmplQuery = qEmplQuery.RetrieveDataSet("P_EmployeeInfo");

Much easier than even the "simple" call I posted earlier, isn't it.  The beauty of this is that it is also an Oracle call (database agnostic:  the same call for Oracle or MS-SQL makes for easier and standardized development) and is cached for 12 hours.  We also have a coding standard that only parameterized Stored Procedures are used for any kind of data access. 

But the most important advantage is that the Query class contains all of the complex coding needed to make this as efficient and "correct" as you know how and never have to think about it again.  This is basic abstraction and Object Oriented Programming fundamentals.  I have used Enterprise Library factories for my calls in Query because of the desire for its good caching and efficient data and network layer calls, but you can use whatever you want. 

In my next series of posts, I will present details of the Query class in order to help build your own.

Monday, August 20, 2007 11:08:46 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
.NET | DataBase | Programming
# Monday, August 13, 2007

I was exploring the statistics on this site the other day and made an interesting discovery.  My rant on The Fall of the Soviet Union, which was done out of annoyance of modern softening of history, is by far the most popular article I have written.  It has received more traffic than all of my other articles.  Which makes me think:  maybe coding is not of interest, but history and military technology.

Then I remember, I post what I know and to help me remember it.  I am not a historian, nor do I play one on TV.

Monday, August 13, 2007 8:27:56 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] -
Blog
<%--
--%>
Statistics
Total Posts: 186
This Year: 0
This Month: 0
This Week: 0
Comments: 72
Locations of visitors to this page
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Frank W Hagen
Sign In
All Content © 2010, Frank W Hagen
Custom DasBlog theme based on 'Business' by Christoph De Baene