<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>{ Duane.Wingett }</title>
    <link>http://www.duanewingett.info/</link>
    <description>.Net Code Monkey</description>
    <language>en-gb</language>
    <copyright>Duane Wingett</copyright>
    <lastBuildDate>Sat, 07 Jan 2012 09:00:42 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>mail@duanewingett.info</managingEditor>
    <webMaster>mail@duanewingett.info</webMaster>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=53b87a58-45ee-4654-8c70-6c7d2684b3ae</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,53b87a58-45ee-4654-8c70-6c7d2684b3ae.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,53b87a58-45ee-4654-8c70-6c7d2684b3ae.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=53b87a58-45ee-4654-8c70-6c7d2684b3ae</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Operators for System.DateTime, continued
from <b><a href="http://www.duanewingett.info/2012/01/06/VBNetNullableDateObjectPart3.aspx">Part
3</a></b><br /><br />
In this article I shall continue to deal with operators, but those specifically which
will allow assignment of System.DateTime values and System.Data.SqlTypes.SqlDateTime
values to the DateTimeNull object or vice-versa. 
<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px">#Region <span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"Operators
for System.DateTime"</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
Converts a System.DateTime structure to a DateTimeNull object.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="value"&gt;A DateTime structure. &lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;returns&gt;A DateTimeNull object whose Value is equal to the combined Date and
TimeOfDay properties of the supplied System.DateTime structure.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Shared</span> Widening
Operator <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">CType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> DateTimeNull
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">New</span> DateTimeNull(value)
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Operator
    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
Converts a DateTimeNull object to a System.DateTime structure.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="value"&gt;a DateTimeNull&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;returns&gt;A System.DateTime structure whose Value is equal to the combined Date
and TimeOfDay properties of the supplied DateTimeNull object.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Shared</span> Widening
Operator <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">CType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> DateTimeNull) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> value.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span> value.InternalDate
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Else</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Throw</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">New</span> InvalidCastException(<span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px">"Cannot
convert Null DateTimeNull to System.DatetTime."</span>)         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Operator
#<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Region</span></pre>
These two widening operators allow us to write the following code without compile
errors:<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Dim</span> nullableDate <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> DateTimeNull <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Nothing</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Dim</span> systemDate <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime
nullableDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> systemDate
systemDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> nullableDate</span></pre>
The first widening operator lets us cast from a System.DateTime to our DateTimeNull
object, and the second one back again. Even with these two operators we cant yet do
comparison checks between the two types. The code below will not compile.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> nullableDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> systemDate <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> systemDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> nullableDate <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span></span></pre>
For that to happen we need to add an equality operators. The code below will allow
the first equality check to compile. Please note for every "equals" operator, you
must provide a "not equals" operator too.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
Determines whether one specified DateTimeNull is equal to another specified DateTime.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d1"&gt;A DateTimeNull.&lt;/param&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d2"&gt;A System.DateTime.&lt;/param&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;returns&gt;&lt;c&gt;true&lt;/c&gt; if d1 is not null and d1 is equal to d2; otherwise,
false.&lt;/returns&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Shared</span> Operator <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d1 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> DateTimeNull, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Boolean</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> d1.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span> (d1.InternalDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> d2) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Else</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">False</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Operator <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
Determines whether one specified DateTimeNull is not equal to another specified DateTime.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d1"&gt;A DateTimeNull.&lt;/param&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d2"&gt;A System.DateTime.&lt;/param&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;returns&gt;&lt;c&gt;true&lt;/c&gt; if d1 is not null and d1 is not equal to d2;
otherwise, false.&lt;/returns&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Shared</span> Operator
&lt;&gt;(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d1 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> DateTimeNull, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Boolean</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> d1.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">Not</span> (d1.InternalDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> d2) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Else</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">False</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Operator</span></pre>
We now need another pair of operators for the second condition.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
Determines whether one specified System.DateTime is equal to another specified DateTimeNull.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d1"&gt;A System.DateTime.&lt;/param&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d2"&gt;A DateTimeNull.&lt;/param&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;returns&gt;&lt;c&gt;true&lt;/c&gt; if d1 is not null and d1 is equal to d2; otherwise,
false.&lt;/returns&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Shared</span> Operator <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d1 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> DateTimeNull) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Boolean</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> d2.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span> (d1 <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> d2.InternalDate) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Else</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">False</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Operator <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
Determines whether one specified System.DateTime is not equal to another specified
DateTimeNull.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d1"&gt;A System.DateTime.&lt;/param&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d2"&gt;A DateTimeNull.&lt;/param&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;returns&gt;&lt;c&gt;true&lt;/c&gt; if d1 is not null and d1 is not equal to d2;
otherwise, false.&lt;/returns&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Shared</span> Operator
&lt;&gt;(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d1 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> .DateTimeNull) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Boolean</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> d2.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">Not</span> (d1 <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px">=</span> d2.InternalDate) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Else</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">False</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Operator</span></pre>
We may now wish to take the time to add in some "greater-than-or-equal-to" and "less-than-or-equal-to"
operators for these two data types.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px">    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
Determines whether one specified DateTimeNull is less than or equal to another specified
System.DateTime.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d1"&gt;A DateTimeNull.&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d2"&gt;A System.DateTime.&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;returns&gt;&lt;c&gt;true&lt;/c&gt; if d1 is not null and d1 is less than or equal
to d2; otherwise, false.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Shared</span> Operator
&lt;=(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d1 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> DateTimeNull, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Boolean</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> d1.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span> (d1.InternalDate
&lt;= d2)         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Else</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">False</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Operator
    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
Determines whether one specified DateTimeNull is greater than or equal to another
specified System.DateTime.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d1"&gt;A DateTimeNull.&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;param name="d2"&gt;A System.DateTime.&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px">'''
&lt;returns&gt;&lt;c&gt;true&lt;/c&gt; if d1 is not null and d1 is greater than or
equal to d2; otherwise, false.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Shared</span> Operator
&gt;=(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d1 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> DateTimeNull, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">ByVal</span> d2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span> System.DateTime) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Boolean</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span> d1.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Then</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span> (d1.InternalDate
&gt;= d2)         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Else</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">False</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">If</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px">End</span> Operator</span></pre>
Remember to provide operators for both left and right evaluation of the DateTimeNull
object.<br /><br /><font size="4">Casting to and from System.Data.SqlTypes.SqlDateTime</font><br /><br />
To allow cross casting between our DateTimeNull object and the System.Data.SqlTypes.SqlDateTime
we just follow the same process and add in the widening and comparison operators as
we did for the System.DateTime, but we do need to keep in mind the upper and lower
date limits of the System.Data.SqlTypes.SqlDateTime structure or an out of range error
could happen at run-time. So evaluate the value and throw an appropriate exception
as necessary in the operator.<br /><br />
In Part 5, we will look at some of the methods we may need to implement<br /><p></p><img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=53b87a58-45ee-4654-8c70-6c7d2684b3ae" /></body>
      <title>VB.Net Nullable Date Object - Part 4</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,53b87a58-45ee-4654-8c70-6c7d2684b3ae.aspx</guid>
      <link>http://www.duanewingett.info/2012/01/07/VBNetNullableDateObjectPart4.aspx</link>
      <pubDate>Sat, 07 Jan 2012 09:00:42 GMT</pubDate>
      <description>Operators for System.DateTime, continued from &lt;b&gt;&lt;a href="http://www.duanewingett.info/2012/01/06/VBNetNullableDateObjectPart3.aspx"&gt;Part
3&lt;/a&gt;&lt;/b&gt;
&lt;br&gt;
&lt;br&gt;
In this article I shall continue to deal with operators, but those specifically which
will allow assignment of System.DateTime values and System.Data.SqlTypes.SqlDateTime
values to the DateTimeNull object or vice-versa. 
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;#Region &lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"Operators
for System.DateTime"&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
Converts a System.DateTime structure to a DateTimeNull object.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="value"&amp;gt;A DateTime structure. &amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;returns&amp;gt;A DateTimeNull object whose Value is equal to the combined Date and
TimeOfDay properties of the supplied System.DateTime structure.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Shared&lt;/span&gt; Widening
Operator &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;CType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; DateTimeNull
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;New&lt;/span&gt; DateTimeNull(value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Operator
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
Converts a DateTimeNull object to a System.DateTime structure.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="value"&amp;gt;a DateTimeNull&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;returns&amp;gt;A System.DateTime structure whose Value is equal to the combined Date
and TimeOfDay properties of the supplied DateTimeNull object.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Shared&lt;/span&gt; Widening
Operator &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;CType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; DateTimeNull) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; value.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; value.InternalDate
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Else&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Throw&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;New&lt;/span&gt; InvalidCastException(&lt;span style="color: #666666; background-color: #e4e4e4; font-family: Courier New; font-size: 11px"&gt;"Cannot
convert Null DateTimeNull to System.DatetTime."&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Operator
#&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Region&lt;/span&gt;&lt;/pre&gt;
These two widening operators allow us to write the following code without compile
errors:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Dim&lt;/span&gt; nullableDate &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; DateTimeNull &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Nothing&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Dim&lt;/span&gt; systemDate &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime
nullableDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; systemDate
systemDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; nullableDate&lt;/span&gt;&lt;/pre&gt;
The first widening operator lets us cast from a System.DateTime to our DateTimeNull
object, and the second one back again. Even with these two operators we cant yet do
comparison checks between the two types. The code below will not compile.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; nullableDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; systemDate &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; systemDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; nullableDate &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
For that to happen we need to add an equality operators. The code below will allow
the first equality check to compile. Please note for every "equals" operator, you
must provide a "not equals" operator too.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
Determines whether one specified DateTimeNull is equal to another specified DateTime.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d1"&amp;gt;A DateTimeNull.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d2"&amp;gt;A System.DateTime.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;returns&amp;gt;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if d1 is not null and d1 is equal to d2; otherwise,
false.&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Shared&lt;/span&gt; Operator &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; DateTimeNull, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Boolean&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; d1.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; (d1.InternalDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; d2) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Else&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;False&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Operator &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
Determines whether one specified DateTimeNull is not equal to another specified DateTime.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d1"&amp;gt;A DateTimeNull.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d2"&amp;gt;A System.DateTime.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;returns&amp;gt;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if d1 is not null and d1 is not equal to d2;
otherwise, false.&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Shared&lt;/span&gt; Operator
&amp;lt;&amp;gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; DateTimeNull, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Boolean&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; d1.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Not&lt;/span&gt; (d1.InternalDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; d2) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Else&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;False&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Operator&lt;/span&gt;&lt;/pre&gt;
We now need another pair of operators for the second condition.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
Determines whether one specified System.DateTime is equal to another specified DateTimeNull.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d1"&amp;gt;A System.DateTime.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d2"&amp;gt;A DateTimeNull.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;returns&amp;gt;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if d1 is not null and d1 is equal to d2; otherwise,
false.&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Shared&lt;/span&gt; Operator &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; DateTimeNull) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Boolean&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; d2.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; (d1 &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; d2.InternalDate) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Else&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;False&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Operator &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
Determines whether one specified System.DateTime is not equal to another specified
DateTimeNull.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d1"&amp;gt;A System.DateTime.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d2"&amp;gt;A DateTimeNull.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;returns&amp;gt;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if d1 is not null and d1 is not equal to d2;
otherwise, false.&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Shared&lt;/span&gt; Operator
&amp;lt;&amp;gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; .DateTimeNull) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Boolean&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; d2.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Not&lt;/span&gt; (d1 &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;=&lt;/span&gt; d2.InternalDate) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Else&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;False&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Operator&lt;/span&gt;&lt;/pre&gt;
We may now wish to take the time to add in some "greater-than-or-equal-to" and "less-than-or-equal-to"
operators for these two data types.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
Determines whether one specified DateTimeNull is less than or equal to another specified
System.DateTime.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d1"&amp;gt;A DateTimeNull.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d2"&amp;gt;A System.DateTime.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;returns&amp;gt;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if d1 is not null and d1 is less than or equal
to d2; otherwise, false.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Shared&lt;/span&gt; Operator
&amp;lt;=(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; DateTimeNull, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Boolean&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; d1.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; (d1.InternalDate
&amp;lt;= d2) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Else&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;False&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Operator
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
Determines whether one specified DateTimeNull is greater than or equal to another
specified System.DateTime.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d1"&amp;gt;A DateTimeNull.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;param name="d2"&amp;gt;A System.DateTime.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;'''
&amp;lt;returns&amp;gt;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if d1 is not null and d1 is greater than or
equal to d2; otherwise, false.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Shared&lt;/span&gt; Operator
&amp;gt;=(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; DateTimeNull, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;ByVal&lt;/span&gt; d2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; System.DateTime) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Boolean&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; d1.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; (d1.InternalDate
&amp;gt;= d2) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Else&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;False&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;If&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px"&gt;End&lt;/span&gt; Operator&lt;/span&gt;&lt;/pre&gt;
Remember to provide operators for both left and right evaluation of the DateTimeNull
object.&lt;br&gt;
&lt;br&gt;
&lt;font size="4"&gt;Casting to and from System.Data.SqlTypes.SqlDateTime&lt;/font&gt;
&lt;br&gt;
&lt;br&gt;
To allow cross casting between our DateTimeNull object and the System.Data.SqlTypes.SqlDateTime
we just follow the same process and add in the widening and comparison operators as
we did for the System.DateTime, but we do need to keep in mind the upper and lower
date limits of the System.Data.SqlTypes.SqlDateTime structure or an out of range error
could happen at run-time. So evaluate the value and throw an appropriate exception
as necessary in the operator.&lt;br&gt;
&lt;br&gt;
In Part 5, we will look at some of the methods we may need to implement&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=53b87a58-45ee-4654-8c70-6c7d2684b3ae" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,53b87a58-45ee-4654-8c70-6c7d2684b3ae.aspx</comments>
      <category>.Net</category>
      <category>Asp.Net</category>
      <category>DateTime</category>
      <category>Operators</category>
      <category>System.Data.SqlTypes.SqlDateTime</category>
      <category>VB.Net</category>
      <category>Widening Operators</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=d506f07b-f991-4e31-bb1c-647b250c1042</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,d506f07b-f991-4e31-bb1c-647b250c1042.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,d506f07b-f991-4e31-bb1c-647b250c1042.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=d506f07b-f991-4e31-bb1c-647b250c1042</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <font size="4">Operators for DBNull.Value,
continues from <a href="http://www.duanewingett.info/2012/01/05/VBNetNullableDateObjectPart2.aspx">Part
2</a></font>
        <br />
        <br />
In this article I shall deal with operators, specifically the ones which will allow
assignment of a value to the DateTimeNull object or vice-versa. For example I want
to be able to run this code:<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Dim</span> nullableDate <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DateTimeNull
= Nothing nullableDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> DBNull.Value</span></pre>
To do this I need to create a couple of shared (non-instance) 'Widening Operator'
for DBNull which will allow the compiler to cast the values.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">#Region <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Operators
for DBNull"</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Converts a System.DBNull object to a DateTimeNull object.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="value"&gt;&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;returns&gt;Returns a DateTimeNull with a Null value.&lt;/returns&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;remarks&gt;&lt;/remarks&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Shared</span> Widening
Operator <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">CType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DBNull) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DateTimeNull
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> DateTimeNull(value)
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Operator
    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Converts a DateTimeNull object to a System.DBNull object.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="value"&gt;&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;returns&gt;&lt;/returns&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;exception cref="InvalidCastException"&gt;Thrown if the DateTimeNull is not null.&lt;/exception&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Shared</span> Widening
Operator <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">CType</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DateTimeNull) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DBNull
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span> value.IsNull <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span> System.DBNull.Value
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Throw</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> InvalidCastException(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"A
non null DateTimeNull cannot be cast to DBNull."</span>)     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Operator
#<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Region</span></pre>
The first operator will return a DBNull.Value to be asigned to the DateTimeNull object,
like so 
<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">nullableDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> DBNull.Value</span></pre>
The second widening operator is required when we want to do some comparisions of the
DateTimeNull to DBNull.Value. To see what I mean, we first need to add an equality
operator.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Performs a logical comparison between a DateTimeNull object </span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
and a System.DBNull object to determine whether they are equal.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="d1"&gt;A DateTimeNull object.&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="d2"&gt;A System.DBNull object.&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;returns&gt;Returns &lt;c&gt;true&lt;/c&gt; if d1 is null.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Shared</span> Operator <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> d1 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DateTimeNull, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> d2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DBNull) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Boolean</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span> d1.IsNull
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Operator</span></pre>
This will allow us to as this question...<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span> (nullableDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> DBNull.Value) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span>         <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'
Do something...</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span></span></pre>
But without the second Widening operator, we can not ask this question, without the
compiler complaining...<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    </span><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span> (DBNull.Value <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> nullableDate) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span>     </span><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    </span><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'
Do something...</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"></span></span><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    </span><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span></span></pre>
Try it and see. If you comment out the second widening operator, then the equality
test with DBNull.Value as the left hand value will not compile. Uncomment it and all
is well!<br /><br />
Finaly, we'll add in a not equal operator.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Performs a logical comparison between a DateTimeNull object </span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
and a System.DBNull object to determine whether they are not equal.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="d1"&gt;A DateTimeNull object.&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="d2"&gt;A System.DBNull object.&lt;/param&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;returns&gt;Returns &lt;c&gt;true&lt;/c&gt; if d1 is not null.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Shared</span> Operator
&lt;&gt;(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> d1 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DateTimeNull, <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> d2 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DBNull) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Boolean</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">Not</span> d1.IsNull
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Operator</span></pre>
In the next artical we'll cover using widening operators for casting to and from System.Datetime
and SqlDateTime. (TBC)...<br /><br /><br /><br /><p></p><img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=d506f07b-f991-4e31-bb1c-647b250c1042" /></body>
      <title> VB.Net Nullable Date Object - Part 3</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,d506f07b-f991-4e31-bb1c-647b250c1042.aspx</guid>
      <link>http://www.duanewingett.info/2012/01/06/VBNetNullableDateObjectPart3.aspx</link>
      <pubDate>Fri, 06 Jan 2012 13:20:15 GMT</pubDate>
      <description>&lt;font size="4"&gt;Operators for DBNull.Value, continues from &lt;a href="http://www.duanewingett.info/2012/01/05/VBNetNullableDateObjectPart2.aspx"&gt;Part
2&lt;/a&gt;&lt;/font&gt;
&lt;br&gt;
&lt;br&gt;
In this article I shall deal with operators, specifically the ones which will allow
assignment of a value to the DateTimeNull object or vice-versa. For example I want
to be able to run this code:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Dim&lt;/span&gt; nullableDate &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DateTimeNull
= Nothing nullableDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; DBNull.Value&lt;/span&gt;&lt;/pre&gt;
To do this I need to create a couple of shared (non-instance) 'Widening Operator'
for DBNull which will allow the compiler to cast the values.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;#Region &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Operators
for DBNull"&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Converts a System.DBNull object to a DateTimeNull object.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="value"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;returns&amp;gt;Returns a DateTimeNull with a Null value.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Shared&lt;/span&gt; Widening
Operator &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;CType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DBNull) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DateTimeNull
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; DateTimeNull(value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Operator
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Converts a DateTimeNull object to a System.DBNull object.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="value"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;exception cref="InvalidCastException"&amp;gt;Thrown if the DateTimeNull is not null.&amp;lt;/exception&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Shared&lt;/span&gt; Widening
Operator &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;CType&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DateTimeNull) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DBNull
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; value.IsNull &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; System.DBNull.Value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Throw&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; InvalidCastException(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"A
non null DateTimeNull cannot be cast to DBNull."&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Operator
#&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Region&lt;/span&gt;&lt;/pre&gt;
The first operator will return a DBNull.Value to be asigned to the DateTimeNull object,
like so 
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;nullableDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; DBNull.Value&lt;/span&gt;&lt;/pre&gt;
The second widening operator is required when we want to do some comparisions of the
DateTimeNull to DBNull.Value. To see what I mean, we first need to add an equality
operator.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Performs a logical comparison between a DateTimeNull object &lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
and a System.DBNull object to determine whether they are equal.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="d1"&amp;gt;A DateTimeNull object.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="d2"&amp;gt;A System.DBNull object.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;returns&amp;gt;Returns &amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if d1 is null.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Shared&lt;/span&gt; Operator &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; d1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DateTimeNull, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; d2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DBNull) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Boolean&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; d1.IsNull
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Operator&lt;/span&gt;&lt;/pre&gt;
This will allow us to as this question...&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; (nullableDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; DBNull.Value) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'
Do something...&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
But without the second Widening operator, we can not ask this question, without the
compiler complaining...&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; (DBNull.Value &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; nullableDate) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'
Do something...&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
Try it and see. If you comment out the second widening operator, then the equality
test with DBNull.Value as the left hand value will not compile. Uncomment it and all
is well!&lt;br&gt;
&lt;br&gt;
Finaly, we'll add in a not equal operator.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Performs a logical comparison between a DateTimeNull object &lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
and a System.DBNull object to determine whether they are not equal.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="d1"&amp;gt;A DateTimeNull object.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="d2"&amp;gt;A System.DBNull object.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;returns&amp;gt;Returns &amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if d1 is not null.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Shared&lt;/span&gt; Operator
&amp;lt;&amp;gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; d1 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DateTimeNull, &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; d2 &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DBNull) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Boolean&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Not&lt;/span&gt; d1.IsNull
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Operator&lt;/span&gt;&lt;/pre&gt;
In the next artical we'll cover using widening operators for casting to and from System.Datetime
and SqlDateTime. (TBC)...&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=d506f07b-f991-4e31-bb1c-647b250c1042" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,d506f07b-f991-4e31-bb1c-647b250c1042.aspx</comments>
      <category>.Net</category>
      <category>Asp.Net</category>
      <category>Casting</category>
      <category>VB.Net</category>
      <category>Widening Operators</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=7e290373-2176-47bd-ad54-b68e2f50c8e0</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,7e290373-2176-47bd-ad54-b68e2f50c8e0.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,7e290373-2176-47bd-ad54-b68e2f50c8e0.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=7e290373-2176-47bd-ad54-b68e2f50c8e0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Constructors Continued from <b><a href="http://www.duanewingett.info/2012/01/04/VBNetNullableDateObjectPart1.aspx">Part
1</a></b>...<br /><br />
We will need a series of constructors which will be used when we create <i>Widening
Operators</i>, later. The first we aill use will accept a parameter value for ticks
as an Int64. We will set the date using our InternalDate property as this will handle
setting the inherited _isNull field for us.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Initializes a new instance of the &lt;see cref="DateTimeNull" /&gt; class to a specified
number of ticks.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="ticks"&gt;The ticks.&lt;/param&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> ticks <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Long</span>)
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">MyBase</span>.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>()
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.InternalDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> System.DateTime(ticks)
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span></span></pre>
The next constructor will take a System.DateTime parameter to construct our object.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Initializes a new instance of the &lt;see cref="DateTimeNull" /&gt; class using the
specified System.DateTime value.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="value"&gt;The value.&lt;/param&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DateTime)
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>(value.Ticks)
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span></span></pre>
The following constructor will take a System.Data.SqlTypes.SqlDateTime parameter to
construct our object.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Initializes a new instance of the &lt;see cref="DateTimeNull" /&gt; class using the
specified System.Data.SqlTypes.SqlDateTime value.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="value"&gt;The value.&lt;/param&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.Data.SqlTypes.SqlDateTime)
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">MyBase</span>.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>()
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Dim</span> dt <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DateTime
        dt <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> Convert.ToDateTime(value)
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.InternalDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> dt
    <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span></span></pre>
The last constructor will take a System.DBNull to construct or object.<br /><br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Initializes a new instance of the &lt;see cref="DateTimeNull" /&gt; class using a
system.DBNull object.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="value"&gt;The value.&lt;/param&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DBNull)
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>(System.DateTime.MinValue)
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">Not</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.IsNull <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.SetIsNull(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">True</span>)
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span></span></pre>
With our constructors done we will take a quick look at some of the properties which
may be useful. Each property will reflect one of the properties that the .Net System.Datetime
object has. <a href="http://en.wikipedia.org/wiki/.NET_Reflector"><i>Reflector</i></a> is
a useful tool for investigating these. Each property will expose the underlying InternalDate's
properties, but first it must check if our object is in the NULL state. I have included
just a few properties so you can see the pattern used.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">    <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Gets the date component of this instance.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;value&gt;A new DateTime with the same date as this instance, and the time value
set to 12:00:00 midnight (00:00:00).&lt;/value&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;exception cref="ArgumentNullException"&gt;Thrown&lt;/exception&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ReadOnly</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span> [<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Date</span>]() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DateTimeNull
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span>                 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> DateTimeNull(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.InternalDate.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Date</span>)
            <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Else</span>                 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Throw</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> ArgumentNullException(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Date
cannot be returned for a null DateTimeNull"</span>)             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Gets the day of the month represented by this instance.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;remarks&gt;The day component, expressed as a value between 1 and 31.&lt;/remarks&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ReadOnly</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Day</span>() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.Int32
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span>                 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.InternalDate.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Day</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Else</span>                 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Throw</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> NullReferenceException(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Day
cannot be expressed for a null DateTimeNull object. "</span>)             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Gets the hour component of the date represented by this instance.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;returns&gt;The hour component, expressed as a value between 0 and 23, inclusive.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ReadOnly</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Hour</span>() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.Int32
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span>                 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.InternalDate.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Hour</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Else</span>                 <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Throw</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span> NullReferenceException(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Hour
cannot be expressed for a null DateTimeNull object. "</span>)             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Gets a System.DateTime object that is set to the current date and time on this computer,
expressed as the local time.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;returns&gt;A DateTime whose value is the current local date and time.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Shared</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ReadOnly</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Now</span>() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DateTime
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span> DateTime.UtcNow.ToLocalTime
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Gets the current date.</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span>     <span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''&lt;returns&gt;A
DateTime set to today's date, with the time component set to 00:00:00.&lt;/returns&gt;</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Shared</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ReadOnly</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Today</span>() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> DateTime
        <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>             <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span> DateTime.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Now</span>.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Date</span>         <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span>     <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span></span></pre><br />
Over time I will add more properties to my DateTimeNull object, as they are required.
Next however, it is time to look at Operators. This will be in <b><a href="http://www.duanewingett.info/2012/01/06/VBNetNullableDateObjectPart3.aspx">Part
3</a></b>.<br /><br /><p></p><img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=7e290373-2176-47bd-ad54-b68e2f50c8e0" /></body>
      <title> VB.Net Nullable Date Object - Part 2</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,7e290373-2176-47bd-ad54-b68e2f50c8e0.aspx</guid>
      <link>http://www.duanewingett.info/2012/01/05/VBNetNullableDateObjectPart2.aspx</link>
      <pubDate>Thu, 05 Jan 2012 13:21:05 GMT</pubDate>
      <description>Constructors Continued from &lt;b&gt;&lt;a href="http://www.duanewingett.info/2012/01/04/VBNetNullableDateObjectPart1.aspx"&gt;Part
1&lt;/a&gt;&lt;/b&gt;...&lt;br&gt;
&lt;br&gt;
We will need a series of constructors which will be used when we create &lt;i&gt;Widening
Operators&lt;/i&gt;, later. The first we aill use will accept a parameter value for ticks
as an Int64. We will set the date using our InternalDate property as this will handle
setting the inherited _isNull field for us.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Initializes a new instance of the &amp;lt;see cref="DateTimeNull" /&amp;gt; class to a specified
number of ticks.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="ticks"&amp;gt;The ticks.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; ticks &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Long&lt;/span&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;MyBase&lt;/span&gt;.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.InternalDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; System.DateTime(ticks)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
The next constructor will take a System.DateTime parameter to construct our object.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Initializes a new instance of the &amp;lt;see cref="DateTimeNull" /&amp;gt; class using the
specified System.DateTime value.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="value"&amp;gt;The value.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DateTime)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;(value.Ticks)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
The following constructor will take a System.Data.SqlTypes.SqlDateTime parameter to
construct our object.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Initializes a new instance of the &amp;lt;see cref="DateTimeNull" /&amp;gt; class using the
specified System.Data.SqlTypes.SqlDateTime value.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="value"&amp;gt;The value.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.Data.SqlTypes.SqlDateTime)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;MyBase&lt;/span&gt;.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Dim&lt;/span&gt; dt &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DateTime
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dt &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Convert.ToDateTime(value)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.InternalDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; dt
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
The last constructor will take a System.DBNull to construct or object.&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Initializes a new instance of the &amp;lt;see cref="DateTimeNull" /&amp;gt; class using a
system.DBNull object.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="value"&amp;gt;The value.&amp;lt;/param&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DBNull)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;(System.DateTime.MinValue)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Not&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.IsNull &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.SetIsNull(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;True&lt;/span&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
With our constructors done we will take a quick look at some of the properties which
may be useful. Each property will reflect one of the properties that the .Net System.Datetime
object has. &lt;a href="http://en.wikipedia.org/wiki/.NET_Reflector"&gt;&lt;i&gt;Reflector&lt;/i&gt;&lt;/a&gt; is
a useful tool for investigating these. Each property will expose the underlying InternalDate's
properties, but first it must check if our object is in the NULL state. I have included
just a few properties so you can see the pattern used.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Gets the date component of this instance.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;value&amp;gt;A new DateTime with the same date as this instance, and the time value
set to 12:00:00 midnight (00:00:00).&amp;lt;/value&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;exception cref="ArgumentNullException"&amp;gt;Thrown&amp;lt;/exception&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; [&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Date&lt;/span&gt;]() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DateTimeNull
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; DateTimeNull(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.InternalDate.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Date&lt;/span&gt;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Else&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Throw&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; ArgumentNullException(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Date
cannot be returned for a null DateTimeNull"&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Gets the day of the month represented by this instance.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;remarks&amp;gt;The day component, expressed as a value between 1 and 31.&amp;lt;/remarks&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Day&lt;/span&gt;() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.Int32
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.InternalDate.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Day&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Else&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Throw&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; NullReferenceException(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Day
cannot be expressed for a null DateTimeNull object. "&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Gets the hour component of the date represented by this instance.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;returns&amp;gt;The hour component, expressed as a value between 0 and 23, inclusive.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Hour&lt;/span&gt;() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.Int32
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.InternalDate.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Hour&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Else&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Throw&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt; NullReferenceException(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Hour
cannot be expressed for a null DateTimeNull object. "&lt;/span&gt;) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Gets a System.DateTime object that is set to the current date and time on this computer,
expressed as the local time.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;returns&amp;gt;A DateTime whose value is the current local date and time.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Shared&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Now&lt;/span&gt;() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DateTime
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; DateTime.UtcNow.ToLocalTime
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Gets the current date.&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''&amp;lt;returns&amp;gt;A
DateTime set to today's date, with the time component set to 00:00:00.&amp;lt;/returns&amp;gt;&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Shared&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Today&lt;/span&gt;() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; DateTime
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; DateTime.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Now&lt;/span&gt;.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Date&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
Over time I will add more properties to my DateTimeNull object, as they are required.
Next however, it is time to look at Operators. This will be in &lt;b&gt;&lt;a href="http://www.duanewingett.info/2012/01/06/VBNetNullableDateObjectPart3.aspx"&gt;Part
3&lt;/a&gt;&lt;/b&gt;.&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=7e290373-2176-47bd-ad54-b68e2f50c8e0" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,7e290373-2176-47bd-ad54-b68e2f50c8e0.aspx</comments>
      <category>.Net</category>
      <category>Asp.Net</category>
      <category>VB.Net</category>
      <category>Widening Operators</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=a34eda7e-d360-4c56-9dab-f845324a3b9c</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,a34eda7e-d360-4c56-9dab-f845324a3b9c.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,a34eda7e-d360-4c56-9dab-f845324a3b9c.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=a34eda7e-d360-4c56-9dab-f845324a3b9c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h3>Background
</h3>
Something I have always been a bit disappointed with in .net is the handling for dates
with null values. I know you can use <font color="#0000FF">Nullable</font>(Of <font color="#7FFFD4">Date</font>)
or <font color="#0000FF">Nullable</font>(Of <font color="#7FFFD4">DateTime</font>)
(or i C# <font color="#0000FF">date?</font> or <font color="#7FFFD4">Datetime</font>?),
but what I want is a date object that I can set a date value, set to Nothing or set
to be equal to DBNull.Value.<br /><br />
So I thought I would document my path to creating the object I need. The code will
be in VB.Net as that is what I curently have to use at my place of work.<br /><br /><h3>Nullable Base Object.
</h3>
First of all as I may need other objects like Int32s and Strings to be nullable in
the future I'll create a nullable base object which all my new objects can inherit
from and will contain some basic implementation. First I am going to create a class
and declare it MustInherit (abstract)so that cannot be used on its own. This will
be the base object that any or all of my nullable objects will inherit from.<br /><br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Option</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Explicit</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">On</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Option</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Strict</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">On</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
This object is the object that all nullable objects should inherit from.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">MustInherit</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Class</span> NullableBaseObject <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Implements</span> System.Data.SqlTypes.INullable
#Region <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Declarations"</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Protected</span> _isNull <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Boolean</span> #<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Region
#Region <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Properties"</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Gets a value indicating whether this instance has value.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;value&gt;&lt;c&gt;true&lt;/c&gt; if this instance has value; otherwise, 
<c>
false
</c>
.&lt;/value&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ReadOnly</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span> HasValue() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Boolean</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">Not</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>._isNull <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Gets a value indicating whether this instance is null.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;value&gt;&lt;c&gt;true&lt;/c&gt; if this instance is null; otherwise, 
<c>
false
</c>
.&lt;/value&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ReadOnly</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span> IsNull() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Boolean</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Implements</span> System.Data.SqlTypes.INullable.IsNull <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>._isNull <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span> #<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Region
#Region <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Methods"</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Sets the internal is-null flag.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;param name="value"&gt;if set to &lt;c&gt;true&lt;/c&gt; [value].</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Protected</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span> SetIsNull(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Boolean</span>) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>._isNull <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"></span> #<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Region <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Class</span></span></pre>
There is a private boolean field <i>_isNull</i> which will hold the nullable state
of the object. There are two properties that refer to this; <i>IsNull</i> and <i>HasValue</i>.
These are in essence opposites of each other but have both been implemented to make
the code more <i>English</i> when using. The <i>IsNull</i> property is implementation
required from the "System.Data.SqlTypes.INullable" interface that the class is going
to implement.<br /><br />
There is one method, The <i>SetIsNull</i> which sets the object state Null and can
be called from inside any classes that inherit from this object.<br /><h3>Nullable DateTime Object
</h3>
The nullable DateTime object will inherit from the <i>NullableBaseObject</i>. There
will be a single private field <i>_internalDate</i> of type <i>System.DateTime</i>.
This will hold our <i>DateTime</i> information when the object is not <i>Null</i>.
This will be accessed by all internal code using a private property <i>InternalDate</i>.
Unlike the <i>System.DateTime </i>which is <i>Structure</i>, I want to be able to
set this object to <i>Nothing</i>, so I will use a <i>Class</i>, not a <i>Structure</i>.<br /><br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Option</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Explicit</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">On</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Option</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Strict</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">On</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Represents nullable an instance in time, typically represented as a date and time.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span> &lt;serializable()&gt; _ <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Class</span> DateTimeNull <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Inherits</span> NullableBaseObject
#Region <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Declarations"</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Private</span> _internalDate <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DateTime
#<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Region
#Region <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Properties"</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Privately gets or sets the internal date. When set IsNull property is set to false.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;value&gt;The internal date.&lt;/value&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Private</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span> InternalDate() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DateTime <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>._internalDate <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Get</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Set</span>(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">ByVal</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span> System.DateTime) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>._internalDate <span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;">=</span> value <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.IsNull <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.SetIsNull(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">False</span>) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Set</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Property</span> #<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Region <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Class</span></span></pre>
We will provide an overridden ToString() method which will return the default ToString()
value for either the System.DateTime object or the System.DBNull.Value, depending
if our object is in a Null state or not.<br /><pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">#Region <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Methods"</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Converts the value of this instance to its equivalent string representation.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;returns&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
A &lt;see cref="System.String"&gt; that represents this instance.</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/returns&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Overrides</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Function</span> ToString() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">As</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">String</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.HasValue <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Then</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Me</span>.InternalDate.ToString <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Else</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Return</span> DBNull.Value.ToString <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">If</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Function</span> #<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Region</span></pre><br />
We will now look at the constructors we wish to use to allow creation of our object.
First we'll look at the default constructor.This constructor initialises the base
object, and then calls the base object's <i>SetIsNull()</i> method to set a null state.<pre><span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;">#Region <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Constructors"</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;summary&gt;</span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
Initializes a new instance of the 
<see cref="Dibware.Core.DateTimeNull">
class, with IsNull = true.
</see></span><span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;">'''
&lt;/summary&gt;</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Public</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">MyBase</span>.<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">New</span>() <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Mybase</span>.SetIsNull(<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">True</span>) <span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">Sub</span><span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"></span> #<span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;">End</span> Region</span></pre><br />
In <a href="http://www.duanewingett.info/2012/01/05/VBNetNullableDateObjectPart2.aspx">Part
2</a>, we'll look at adding more constructors that we will need when creating casting
operators later. 
<br /><img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=a34eda7e-d360-4c56-9dab-f845324a3b9c" /></body>
      <title>VB.Net Nullable Date Object - Part 1</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,a34eda7e-d360-4c56-9dab-f845324a3b9c.aspx</guid>
      <link>http://www.duanewingett.info/2012/01/04/VBNetNullableDateObjectPart1.aspx</link>
      <pubDate>Wed, 04 Jan 2012 13:20:09 GMT</pubDate>
      <description>

&lt;h3&gt;Background
&lt;/h3&gt;
Something I have always been a bit disappointed with in .net is the handling for dates
with null values. I know you can use &lt;font color="#0000FF"&gt;Nullable&lt;/font&gt;(Of &lt;font color="#7FFFD4"&gt;Date&lt;/font&gt;)
or &lt;font color="#0000FF"&gt;Nullable&lt;/font&gt;(Of &lt;font color="#7FFFD4"&gt;DateTime&lt;/font&gt;)
(or i C# &lt;font color="#0000FF"&gt;date?&lt;/font&gt; or &lt;font color="#7FFFD4"&gt;Datetime&lt;/font&gt;?),
but what I want is a date object that I can set a date value, set to Nothing or set
to be equal to DBNull.Value.&lt;br&gt;
&lt;br&gt;
So I thought I would document my path to creating the object I need. The code will
be in VB.Net as that is what I curently have to use at my place of work.&lt;br&gt;
&lt;br&gt;
&lt;h3&gt;Nullable Base Object.
&lt;/h3&gt;
First of all as I may need other objects like Int32s and Strings to be nullable in
the future I'll create a nullable base object which all my new objects can inherit
from and will contain some basic implementation. First I am going to create a class
and declare it MustInherit (abstract)so that cannot be used on its own. This will
be the base object that any or all of my nullable objects will inherit from.&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Option&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Explicit&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;On&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Option&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Strict&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;On&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
This object is the object that all nullable objects should inherit from.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;MustInherit&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Class&lt;/span&gt; NullableBaseObject &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Implements&lt;/span&gt; System.Data.SqlTypes.INullable
#Region &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Declarations"&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Protected&lt;/span&gt; _isNull &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Boolean&lt;/span&gt; #&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Region
#Region &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Properties"&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Gets a value indicating whether this instance has value.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;value&amp;gt;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if this instance has value; otherwise, 
&lt;c&gt;
false
&lt;/c&gt;
.&amp;lt;/value&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; HasValue() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Boolean&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Not&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;._isNull &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Gets a value indicating whether this instance is null.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;value&amp;gt;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if this instance is null; otherwise, 
&lt;c&gt;
false
&lt;/c&gt;
.&amp;lt;/value&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ReadOnly&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; IsNull() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Boolean&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Implements&lt;/span&gt; System.Data.SqlTypes.INullable.IsNull &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;._isNull &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; #&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Region
#Region &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Methods"&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Sets the internal is-null flag.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;param name="value"&amp;gt;if set to &amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; [value].&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Protected&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt; SetIsNull(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Boolean&lt;/span&gt;) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;._isNull &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt; #&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Region &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Class&lt;/span&gt;&lt;/span&gt; &lt;/pre&gt;
There is a private boolean field &lt;i&gt;_isNull&lt;/i&gt; which will hold the nullable state
of the object. There are two properties that refer to this; &lt;i&gt;IsNull&lt;/i&gt; and &lt;i&gt;HasValue&lt;/i&gt;.
These are in essence opposites of each other but have both been implemented to make
the code more &lt;i&gt;English&lt;/i&gt; when using. The &lt;i&gt;IsNull&lt;/i&gt; property is implementation
required from the "System.Data.SqlTypes.INullable" interface that the class is going
to implement.&lt;br&gt;
&lt;br&gt;
There is one method, The &lt;i&gt;SetIsNull&lt;/i&gt; which sets the object state Null and can
be called from inside any classes that inherit from this object.&lt;br&gt;
&lt;h3&gt;Nullable DateTime Object
&lt;/h3&gt;
The nullable DateTime object will inherit from the &lt;i&gt;NullableBaseObject&lt;/i&gt;. There
will be a single private field &lt;i&gt;_internalDate&lt;/i&gt; of type &lt;i&gt;System.DateTime&lt;/i&gt;.
This will hold our &lt;i&gt;DateTime&lt;/i&gt; information when the object is not &lt;i&gt;Null&lt;/i&gt;.
This will be accessed by all internal code using a private property &lt;i&gt;InternalDate&lt;/i&gt;.
Unlike the &lt;i&gt;System.DateTime &lt;/i&gt;which is &lt;i&gt;Structure&lt;/i&gt;, I want to be able to
set this object to &lt;i&gt;Nothing&lt;/i&gt;, so I will use a &lt;i&gt;Class&lt;/i&gt;, not a &lt;i&gt;Structure&lt;/i&gt;.&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Option&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Explicit&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;On&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Option&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Strict&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;On&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Represents nullable an instance in time, typically represented as a date and time.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &amp;lt;serializable()&amp;gt; _ &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Class&lt;/span&gt; DateTimeNull &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Inherits&lt;/span&gt; NullableBaseObject
#Region &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Declarations"&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Private&lt;/span&gt; _internalDate &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DateTime
#&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Region
#Region &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Properties"&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Privately gets or sets the internal date. When set IsNull property is set to false.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;value&amp;gt;The internal date.&amp;lt;/value&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Private&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; InternalDate() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DateTime &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;._internalDate &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Get&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Set&lt;/span&gt;(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;ByVal&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; System.DateTime) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;._internalDate &lt;span style="color: Red; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; value &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.IsNull &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.SetIsNull(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;False&lt;/span&gt;) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Set&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Property&lt;/span&gt; #&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Region &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Class&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
We will provide an overridden ToString() method which will return the default ToString()
value for either the System.DateTime object or the System.DBNull.Value, depending
if our object is in a Null state or not.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;#Region &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Methods"&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Converts the value of this instance to its equivalent string representation.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;returns&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
A &amp;lt;see cref="System.String"&amp;gt; that represents this instance.&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Overrides&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Function&lt;/span&gt; ToString() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;As&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;String&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.HasValue &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Then&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Me&lt;/span&gt;.InternalDate.ToString &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Else&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Return&lt;/span&gt; DBNull.Value.ToString &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;If&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Function&lt;/span&gt; #&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Region&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
We will now look at the constructors we wish to use to allow creation of our object.
First we'll look at the default constructor.This constructor initialises the base
object, and then calls the base object's &lt;i&gt;SetIsNull()&lt;/i&gt; method to set a null state.&lt;pre&gt;&lt;span style="color: Black; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;#Region &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Constructors"&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
Initializes a new instance of the 
&lt;see cref="Dibware.Core.DateTimeNull"&gt;
class, with IsNull = true.
&lt;/see&gt;
&lt;/span&gt; &lt;span style="color: Green; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Public&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;MyBase&lt;/span&gt;.&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;New&lt;/span&gt;() &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Mybase&lt;/span&gt;.SetIsNull(&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;True&lt;/span&gt;) &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; &lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;Sub&lt;/span&gt;&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;/span&gt; #&lt;span style="color: Blue; background-color: Transparent; font-family: Courier New; font-size: 11px;"&gt;End&lt;/span&gt; Region&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
In &lt;a href="http://www.duanewingett.info/2012/01/05/VBNetNullableDateObjectPart2.aspx"&gt;Part
2&lt;/a&gt;, we'll look at adding more constructors that we will need when creating casting
operators later. 
&lt;br&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=a34eda7e-d360-4c56-9dab-f845324a3b9c" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,a34eda7e-d360-4c56-9dab-f845324a3b9c.aspx</comments>
      <category>.Net</category>
      <category>Asp.Net</category>
      <category>DateTime</category>
      <category>Nullable</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=c29b1723-55e3-4d7c-ad69-d0fbbd3e6133</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,c29b1723-55e3-4d7c-ad69-d0fbbd3e6133.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,c29b1723-55e3-4d7c-ad69-d0fbbd3e6133.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=c29b1723-55e3-4d7c-ad69-d0fbbd3e6133</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h2>Background
</h2>
        <p>
Over the last week I have been periodically trying to get SQl Server 2005 express
and SQL Server 2008 express to run side by side. One of the issues is there is a restriction
when trying to instal SQL 2008 Express over the top of 2005 with the "SQL 2008 Install
Blocked..." message
</p>
        <p>
To get around this I managed to find information on a blog post (I will try to find
and post a link to it) explaining how to move the registry entry for 2005, just while
installing 2008.
</p>
        <p>
The all inportant registry entry is:<br /><br />
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server<br /></p>
        <p>
Before installing SQL Server 2008 Express rename the '90' node to '90_old' and then
install as normal. Once the installation has taken place refersh the node list and
yiou will see a new '90' has appeared. Rename that to something else. I chose'70'
as I will never be installing SQl Server 7 on this machine! Rename yiour '90_old'
back to '90' and restart the machine.
</p>
        <p>
When you install 2008 remember to choose a different instance name than the one you
choose for SQL 2005
</p>
        <p>
One thing to note is you may wish to detach your SQL Server 2005 databases first as
I now seem to be unable to connect to one of them on my SQL 2005 instance. I need
to look into how to reconnect this database!
</p>
        <p>
          <strong>Update:</strong> It turns out that I had to give some more permissions to
the database mdf files. I had to add "NETWORK SERVICE" and give it full control. I
was then able to detach and reattach the databse and I can now see all databases in
both 2005 and 2008 Management Studio Express versions.
</p>
        <img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=c29b1723-55e3-4d7c-ad69-d0fbbd3e6133" />
      </body>
      <title>Dual running SQL Server 2005 and 2008 Express on Windows 7</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,c29b1723-55e3-4d7c-ad69-d0fbbd3e6133.aspx</guid>
      <link>http://www.duanewingett.info/2011/09/24/DualRunningSQLServer2005And2008ExpressOnWindows7.aspx</link>
      <pubDate>Sat, 24 Sep 2011 07:56:43 GMT</pubDate>
      <description>&lt;h2&gt;Background
&lt;/h2&gt;
&lt;p&gt;
Over the last week I have been periodically trying to get SQl Server 2005 express
and SQL Server 2008 express to run side by side. One of the issues is there is a restriction
when trying to instal SQL 2008 Express over the top of 2005 with the "SQL 2008 Install
Blocked..." message
&lt;/p&gt;
&lt;p&gt;
To get around this I managed to find information on a blog post (I will try to find
and post a link to it) explaining how to move the registry entry for 2005, just while
installing 2008.
&lt;/p&gt;
&lt;p&gt;
The all inportant registry entry is:&lt;br /&gt;
&lt;br /&gt;
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SQL Server&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
Before installing SQL Server 2008 Express rename the '90' node to '90_old' and then
install as normal. Once the installation has taken place refersh the node list and
yiou will see a new '90' has appeared. Rename that to something else. I chose'70'
as I will never be installing SQl Server 7 on this machine! Rename yiour '90_old'
back to '90' and restart the machine.
&lt;/p&gt;
&lt;p&gt;
When you install 2008 remember to choose a different instance name than the one you
choose for SQL 2005
&lt;/p&gt;
&lt;p&gt;
One thing to note is you may wish to detach your SQL Server 2005 databases first as
I now seem to be unable to connect to one of them on my SQL 2005 instance. I need
to look into how to reconnect this database!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Update:&lt;/strong&gt; It turns out that I had to give some more permissions to
the database mdf files. I had to add "NETWORK SERVICE" and give it full control. I
was then able to detach and reattach the databse and I can now see all databases in
both 2005 and 2008 Management Studio Express versions.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=c29b1723-55e3-4d7c-ad69-d0fbbd3e6133" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,c29b1723-55e3-4d7c-ad69-d0fbbd3e6133.aspx</comments>
      <category>Database</category>
      <category>SQL Server</category>
      <category>SQL Server 2005 Express</category>
      <category>SQL Server 2008 Express</category>
      <category>Windows 7</category>
      <category>Permissions</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=c3e30fbf-ccc8-4831-9f20-abee939e713b</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,c3e30fbf-ccc8-4831-9f20-abee939e713b.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,c3e30fbf-ccc8-4831-9f20-abee939e713b.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=c3e30fbf-ccc8-4831-9f20-abee939e713b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Due to comment abuse, comments have now been disabled.
</p>
        <p>
 
</p>
        <p>
Sorry.
</p>
        <p>
D.
</p>
        <img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=c3e30fbf-ccc8-4831-9f20-abee939e713b" />
      </body>
      <title>Comment Abuse</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,c3e30fbf-ccc8-4831-9f20-abee939e713b.aspx</guid>
      <link>http://www.duanewingett.info/2011/04/20/CommentAbuse.aspx</link>
      <pubDate>Wed, 20 Apr 2011 17:29:54 GMT</pubDate>
      <description>&lt;p&gt;
Due to comment abuse, comments have now been disabled.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Sorry.
&lt;/p&gt;
&lt;p&gt;
D.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=c3e30fbf-ccc8-4831-9f20-abee939e713b" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,c3e30fbf-ccc8-4831-9f20-abee939e713b.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=451dff60-23b1-445c-8e03-10302ae6446f</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,451dff60-23b1-445c-8e03-10302ae6446f.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,451dff60-23b1-445c-8e03-10302ae6446f.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=451dff60-23b1-445c-8e03-10302ae6446f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h2>Create VB.Net class from Sql Server table
</h2>
        <p>
Have you ever wanted to be able to create VB.Net classes that have fields that emulate
the columns in your SQL server tables?
</p>
        <p>
Well if you have, then read on...
</p>
        <p>
A little project I am working on at home has a table with a lot of columns, and the
architecture I am writing the application to requires an entity which will emulate
this table. I couldn't bear the idea of writing all those private fields and public
properties out, even with Visual Studios "Property" snippet.
</p>
        <p>
So I got to thinking, can I query the database and output a class structure in VB.Net
language. Well with the help of SQL Server Cursors, yes I can.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">----------------------------------</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--
DW: 11/04/2011</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--
This script will build a class file with </span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--
private fields and public properties from</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--
the table specified in the @TableName variable.</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">----------------------------------</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> @TableName <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">varchar</span>(50) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> @TableName
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'MyTable'</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">NOCOUNT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ON</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--
Hide row count so printed output is not affected</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> @DataTypeName <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">varchar</span>(50) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> @NewLine <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">char</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> @ColumnName <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">varchar</span>(50) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> @DataType <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">varchar</span>(50) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> @FieldName <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">varchar</span>(50) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">--SET</span> @NewLine
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">char</span>(13) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--
Start Output</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--PRINT
'' + @NewLine;</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Public
Class '</span> + @TableName; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'#Region
"Declarations"'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--
Declarations</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> DeclarationCursor <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">CURSOR</span> SCROLL <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FOR</span>     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SELECT</span>         columns.name
[ColumnName],         <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">CASE</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 34 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Byte[]'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 35 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'String'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 36 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'System.Guid'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 48 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Byte'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 52 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Short'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 56 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Integer'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 58 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'System.DateTime'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 59 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'float'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 60 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Decimal'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 61 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'System.DateTime'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 62 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'double'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 98 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Object'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 99 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'String'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 104 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Boolean'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 106 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Decimal'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 108 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Decimal'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 122 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Decimal'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 127 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'long'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 165 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Byte[]'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 167 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'String'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 173 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Byte[]'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 175 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'string'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 189 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'Long'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 231 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'String'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 239 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'String'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 241 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'String'</span>             <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHEN</span> columns.system_type_id
= 241 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">THEN</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'String'</span>         <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">END</span> [DataType] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> sys.tables
tables <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INNER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: silver; FONT-SIZE: 11px">JOIN</span> sys.schemas
schemas <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ON</span> (tables.schema_id
= schemas.schema_id ) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INNER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: silver; FONT-SIZE: 11px">JOIN</span> sys.columns
columns <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ON</span> (columns.<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">object_id</span> =
tables.<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">object_id</span>) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHERE</span>     tables.name
= @TableName <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ORDER</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BY</span>     columns.<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">object_id</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ASC</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">OPEN</span> DeclarationCursor; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FETCH</span> NEXT <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> DeclarationCursor <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> @ColumnName,
@DataType; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHILE</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">@@FETCH_STATUS</span> =
0 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BEGIN</span>     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> @FieldName
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'_'</span> + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">LOWER</span>(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUBSTRING</span>(@ColumnName,
1,1)) + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUBSTRING</span>(@ColumnName,
2, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">LEN</span>(@ColumnName)-1) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
Private '</span> + @FieldName + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
As '</span> + @DataType;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FETCH</span> NEXT <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> DeclarationCursor
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> @ColumnName,
@DataType; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">END</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'#End
Region'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'#Region
"Properties"'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FETCH</span> FIRST <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> DeclarationCursor <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> @ColumnName,
@DataType; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHILE</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">@@FETCH_STATUS</span> =
0 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BEGIN</span>     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> @FieldName
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'_'</span> + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">LOWER</span>(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUBSTRING</span>(@ColumnName,
1,1)) + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUBSTRING</span>(@ColumnName,
2, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">LEN</span>(@ColumnName)-1) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
Public Property '</span> + @ColumnName + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
As '</span> + @DataType;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
Get'</span>;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
Return '</span> + @FieldName;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
End Get'</span>;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
Set'</span>;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
'</span> + @FieldName + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
= value'</span>;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
End Set'</span>;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
End Property'</span>;     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>;
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FETCH</span> NEXT <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> DeclarationCursor
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> @ColumnName,
@DataType; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">END</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'#End
Region'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DECLARE</span> @FIELDS <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">varchar</span>(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">max</span>) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> @FIELDS
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FETCH</span> FIRST <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> DeclarationCursor <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> @ColumnName,
@DataType; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">WHILE</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">@@FETCH_STATUS</span> =
0 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">BEGIN</span>     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> @FieldName
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">LOWER</span>(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUBSTRING</span>(@ColumnName,
1,1)) + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUBSTRING</span>(@ColumnName,
2, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">LEN</span>(@ColumnName)-1)
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> @FIELDS
= @FIELDS + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'byval
'</span> + @FieldName + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
as '</span> + @DataType + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">',
'</span>     <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FETCH</span> NEXT <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">FROM</span> DeclarationCursor
    <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">INTO</span> @ColumnName,
@DataType; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">END</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">SET</span> @FIELDS
= <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">SUBSTRING</span>(@FIELDS,
1, (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px">LEN</span>(@FIELDS)
- 1)) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'#Region
"Constructors"'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
Public Sub New()'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
End Sub'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
Public Sub New('</span> + @FIELDS + <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">')'</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
Me.New()'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'
End Sub'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'#End
Region'</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">''</span>; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">CLOSE</span> DeclarationCursor; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">DEALLOCATE</span> DeclarationCursor; <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px">--
End of Class</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">PRINT</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">'End
Class'</span>; </span>
        </pre>
        <p>
          <font size="2">The class also includes a parametricised public constructor, too.</font>
        </p>
        <p>
          <font size="1">( Feel free to use all or any of this code how ever you choose. Feel
free to post it on your own blog, as long as you credit this page with a back link.
)</font>
        </p>
        <p>
I hope that this snippet of SQL will help you as much as it has helped me today.
</p>
        <p>
Best regards,<br />
Duane.
</p>
        <img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=451dff60-23b1-445c-8e03-10302ae6446f" />
      </body>
      <title>Create VB.Net class from Sql Server table</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,451dff60-23b1-445c-8e03-10302ae6446f.aspx</guid>
      <link>http://www.duanewingett.info/2011/04/12/CreateVBNetClassFromSqlServerTable.aspx</link>
      <pubDate>Tue, 12 Apr 2011 19:29:18 GMT</pubDate>
      <description>&lt;h2&gt;Create VB.Net class from Sql Server table
&lt;/h2&gt;
&lt;p&gt;
Have you ever wanted to be able to create VB.Net classes that have fields that emulate
the columns in your SQL server tables?
&lt;/p&gt;
&lt;p&gt;
Well if you have, then read on...
&lt;/p&gt;
&lt;p&gt;
A little project I am working on at home has a table with a lot of columns, and the
architecture I am writing the application to requires an entity which will emulate
this table. I couldn't bear the idea of writing all those private fields and public
properties out, even with Visual Studios "Property" snippet.
&lt;/p&gt;
&lt;p&gt;
So I got to thinking, can I query the database and output a class structure in VB.Net
language. Well with the help of SQL Server Cursors, yes I can.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;----------------------------------&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--
DW: 11/04/2011&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--
This script will build a class file with &lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--
private fields and public properties from&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--
the table specified in the @TableName variable.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;----------------------------------&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; @TableName &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;varchar&lt;/span&gt;(50) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; @TableName
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'MyTable'&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;NOCOUNT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ON&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--
Hide row count so printed output is not affected&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; @DataTypeName &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;varchar&lt;/span&gt;(50) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; @NewLine &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;char&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; @ColumnName &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;varchar&lt;/span&gt;(50) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; @DataType &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;varchar&lt;/span&gt;(50) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; @FieldName &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;varchar&lt;/span&gt;(50) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;--SET&lt;/span&gt; @NewLine
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;char&lt;/span&gt;(13) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--
Start Output&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--PRINT
'' + @NewLine;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Public
Class '&lt;/span&gt; + @TableName; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'#Region
"Declarations"'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--
Declarations&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; DeclarationCursor &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;CURSOR&lt;/span&gt; SCROLL &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FOR&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SELECT&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;columns.name
[ColumnName], &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;CASE&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 34 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Byte[]'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 35 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'String'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 36 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'System.Guid'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 48 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Byte'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 52 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Short'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 56 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Integer'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 58 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'System.DateTime'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 59 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'float'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 60 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Decimal'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 61 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'System.DateTime'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 62 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'double'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 98 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Object'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 99 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'String'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 104 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Boolean'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 106 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Decimal'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 108 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Decimal'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 122 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Decimal'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 127 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'long'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 165 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Byte[]'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 167 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'String'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 173 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Byte[]'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 175 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'string'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 189 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'Long'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 231 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'String'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 239 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'String'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 241 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'String'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHEN&lt;/span&gt; columns.system_type_id
= 241 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;THEN&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'String'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;END&lt;/span&gt; [DataType] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; sys.tables
tables &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INNER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: silver; FONT-SIZE: 11px"&gt;JOIN&lt;/span&gt; sys.schemas
schemas &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ON&lt;/span&gt; (tables.schema_id
= schemas.schema_id ) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INNER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: silver; FONT-SIZE: 11px"&gt;JOIN&lt;/span&gt; sys.columns
columns &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ON&lt;/span&gt; (columns.&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;object_id&lt;/span&gt; =
tables.&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;object_id&lt;/span&gt;) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHERE&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tables.name
= @TableName &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ORDER&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BY&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;columns.&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;object_id&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ASC&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;OPEN&lt;/span&gt; DeclarationCursor; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FETCH&lt;/span&gt; NEXT &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; DeclarationCursor &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; @ColumnName,
@DataType; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHILE&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;@@FETCH_STATUS&lt;/span&gt; =
0 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BEGIN&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; @FieldName
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'_'&lt;/span&gt; + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;LOWER&lt;/span&gt;(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUBSTRING&lt;/span&gt;(@ColumnName,
1,1)) + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUBSTRING&lt;/span&gt;(@ColumnName,
2, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;LEN&lt;/span&gt;(@ColumnName)-1) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
Private '&lt;/span&gt; + @FieldName + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
As '&lt;/span&gt; + @DataType; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FETCH&lt;/span&gt; NEXT &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; DeclarationCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; @ColumnName,
@DataType; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;END&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'#End
Region'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'#Region
"Properties"'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FETCH&lt;/span&gt; FIRST &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; DeclarationCursor &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; @ColumnName,
@DataType; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHILE&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;@@FETCH_STATUS&lt;/span&gt; =
0 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BEGIN&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; @FieldName
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'_'&lt;/span&gt; + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;LOWER&lt;/span&gt;(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUBSTRING&lt;/span&gt;(@ColumnName,
1,1)) + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUBSTRING&lt;/span&gt;(@ColumnName,
2, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;LEN&lt;/span&gt;(@ColumnName)-1) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
Public Property '&lt;/span&gt; + @ColumnName + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
As '&lt;/span&gt; + @DataType; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
Get'&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
Return '&lt;/span&gt; + @FieldName; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
End Get'&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
Set'&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
'&lt;/span&gt; + @FieldName + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
= value'&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
End Set'&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
End Property'&lt;/span&gt;; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FETCH&lt;/span&gt; NEXT &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; DeclarationCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; @ColumnName,
@DataType; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;END&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'#End
Region'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DECLARE&lt;/span&gt; @FIELDS &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;varchar&lt;/span&gt;(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;max&lt;/span&gt;) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; @FIELDS
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FETCH&lt;/span&gt; FIRST &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; DeclarationCursor &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; @ColumnName,
@DataType; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;WHILE&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;@@FETCH_STATUS&lt;/span&gt; =
0 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;BEGIN&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; @FieldName
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;LOWER&lt;/span&gt;(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUBSTRING&lt;/span&gt;(@ColumnName,
1,1)) + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUBSTRING&lt;/span&gt;(@ColumnName,
2, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;LEN&lt;/span&gt;(@ColumnName)-1)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; @FIELDS
= @FIELDS + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'byval
'&lt;/span&gt; + @FieldName + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
as '&lt;/span&gt; + @DataType + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;',
'&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FETCH&lt;/span&gt; NEXT &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;FROM&lt;/span&gt; DeclarationCursor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;INTO&lt;/span&gt; @ColumnName,
@DataType; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;END&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;SET&lt;/span&gt; @FIELDS
= &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;SUBSTRING&lt;/span&gt;(@FIELDS,
1, (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: fuchsia; FONT-SIZE: 11px"&gt;LEN&lt;/span&gt;(@FIELDS)
- 1)) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'#Region
"Constructors"'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
Public Sub New()'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
End Sub'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
Public Sub New('&lt;/span&gt; + @FIELDS + &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;')'&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
Me.New()'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'
End Sub'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'#End
Region'&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;''&lt;/span&gt;; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;CLOSE&lt;/span&gt; DeclarationCursor; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;DEALLOCATE&lt;/span&gt; DeclarationCursor; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: teal; FONT-SIZE: 11px"&gt;--
End of Class&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;PRINT&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;'End
Class'&lt;/span&gt;; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;font size=2&gt;The class also includes a parametricised public constructor, too.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;( Feel free to use all or any of this code how ever you choose. Feel
free to post it on your own blog, as long as you credit this page with a back link.
)&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
I hope that this snippet of SQL will help you as much as it has helped me today.
&lt;/p&gt;
&lt;p&gt;
Best regards,&lt;br&gt;
Duane.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=451dff60-23b1-445c-8e03-10302ae6446f" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,451dff60-23b1-445c-8e03-10302ae6446f.aspx</comments>
      <category>.Net</category>
      <category>Asp.Net</category>
      <category>Classes</category>
      <category>Cursor</category>
      <category>Database</category>
      <category>SQL</category>
      <category>SQL Server</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=5967e8bc-786b-4dba-bb90-a68eb3c13017</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,5967e8bc-786b-4dba-bb90-a68eb3c13017.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,5967e8bc-786b-4dba-bb90-a68eb3c13017.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=5967e8bc-786b-4dba-bb90-a68eb3c13017</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h3>Mixed Scope Properties in .Net
</h3>
        <p>
There may be a time when you want to have mixed scope for your "Getters" and "Setters"
in a property. For those of you who are not familiar with the syntax here it is
</p>
        <p>
VB:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Property</span> MyProperty <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">as</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">String</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Get</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Return</span> _myField <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Get</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Set</span> _myField <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> Value <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Set</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Property</span></span>
        </pre>
        <p>
This example allows a public "Getter" and a private "Setter". 
</p>
        <p>
The same can be done in C#:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> MyProperty
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">get</span> { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> _myField;
} <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">set</span> {
_myField <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> value;
} }</span>
        </pre>
        <p>
Hope you find that useful.
</p>
        <p>
Regards,
</p>
        <p>
Dib.
</p>
        <img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=5967e8bc-786b-4dba-bb90-a68eb3c13017" />
      </body>
      <title>Mixed Scope Properties in .Net</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,5967e8bc-786b-4dba-bb90-a68eb3c13017.aspx</guid>
      <link>http://www.duanewingett.info/2010/09/02/MixedScopePropertiesInNet.aspx</link>
      <pubDate>Thu, 02 Sep 2010 18:06:44 GMT</pubDate>
      <description>&lt;h3&gt;Mixed Scope Properties in .Net
&lt;/h3&gt;
&lt;p&gt;
There may be a time when you want to have mixed scope for your "Getters" and "Setters"
in a property. For those of you who are not familiar with the syntax here it is
&lt;/p&gt;
&lt;p&gt;
VB:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Property&lt;/span&gt; MyProperty &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;as&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;String&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Get&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Return&lt;/span&gt; _myField &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Get&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Set&lt;/span&gt; _myField &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; Value &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Set&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Property&lt;/span&gt; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
This example allows a public "Getter" and a private "Setter". 
&lt;/p&gt;
&lt;p&gt;
The same can be done in C#:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; MyProperty
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;get&lt;/span&gt; { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; _myField;
} &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;set&lt;/span&gt; {
_myField &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; value;
} }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Hope you find that useful.
&lt;/p&gt;
&lt;p&gt;
Regards,
&lt;/p&gt;
&lt;p&gt;
Dib.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=5967e8bc-786b-4dba-bb90-a68eb3c13017" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,5967e8bc-786b-4dba-bb90-a68eb3c13017.aspx</comments>
      <category>.Net</category>
      <category>Asp.Net</category>
      <category>C#</category>
      <category>Scope</category>
      <category>VB Script</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=3c6c00f1-740c-4bf2-b6ec-3875ad339beb</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,3c6c00f1-740c-4bf2-b6ec-3875ad339beb.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,3c6c00f1-740c-4bf2-b6ec-3875ad339beb.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=3c6c00f1-740c-4bf2-b6ec-3875ad339beb</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
VB.Net Single Instance application on Terminal Server 
</p>
        <p>
Yesterday at work I spent nearly the whole day bashing my head against a wall trying
to replicate functionality that our original VB6 application had into the new .Net
conversion. The orginal VB6 application used "<strong>App.PrevInstance</strong>"
to determine if another instance was running or not. This appeared to work for multiple
users on Terminal Servers, so each user could run an instance of the app, but it would
warn if they tried to open another.
</p>
        <p>
VB.Net does not appear to have such direct functionality. Looking on the web provided
various 'solutions' to the problem. However each one seemed to have an 'issue' with
our scenario. By the afternoon I was looking at the <strong>Mutex</strong> objects
which a lot of people seemed to find worked for them. However for me I was getting
an "<span name="subject">Object synchronization method was called from an unsynchronized
block of code</span>" error when closing the second instance onwards.
</p>
        <p>
Looking into the <strong>Mutex</strong> object in a bit more depth it seemed that
maybe it was not the right object for our purpose but maybe the <strong>Semaphore</strong> object
would be better.
</p>
        <p>
In the end the solution I used was to use a named Semaphore. When the application
first instance runs it would attempt to open the named Semaphore and if it did
not exist, assume it was the first instance and create one. The second instance when
run would again look for and open the named Semaphore and if it exists and it manages
to open it then it would assmue it is a second instance of the application.
</p>
        <p>
By prefixing the Semaphorename with "Local\" it will allow each <strong>Terminal Server</strong> session
to have it's own Semaphore so each remote user would not affected by another.
</p>
        <p>
The elements of the code I used are below.
</p>
        <p>
Imports:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Imports</span> System.Threading</span>
        </pre>
        <p>
Declarations:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Private</span> SingleInstanceSemaphore <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span> Semaphore <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Nothing</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
This needs to live for the life of the application</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Const</span> MAX_SESSION_INSTANCES <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Integer</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 1 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Private</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Const</span> SEMAPHORE_NAME <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">String</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"{9A49BB2C-45D2-4bb9-B38E-74F9DB612B96}"</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
Unique for each application</span></span>
        </pre>
        <p>
Main Method:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'''
&lt;summary&gt;</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'''
This is the main application entrance point.</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'''
&lt;/summary&gt;</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Sub</span> Main() <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
We need a name for the semaphore that is specific to to the Application / User combination</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
We prefix the semaphoreName with "Local\" to allow this to run under terminal services. </span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
The "Local\" prefix forces this into local user space. </span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
If we want to forbid this in TS, use the "Global\" prefix.</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Dim</span> semaphorePrefix <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">String</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Local"</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
Or "Global" if required</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Dim</span> semaphoreName <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">String</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">String</span>.<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Format</span>(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"{0}\{1}{2}"</span>,
semaphorePrefix, SEMAPHORE_NAME, Environment.UserName) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Dim</span> anotherInstanceRunningForUser <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Boolean</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">True</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Dim</span> runAnotherDialogResult <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span> DialogResult <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> DialogResult.No <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Dim</span> mainForm <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span> Form1 <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Nothing</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Try</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Try</span> SingleInstanceSemaphore <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> Semaphore.OpenExisting(semaphoreName) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Catch</span> ex <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span> Exception
anotherInstanceRunningForUser <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">False</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Try</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">If</span> (anotherInstanceRunningForUser <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">False</span>) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Then</span> SingleInstanceSemaphore <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">New</span> Semaphore(0,
MAX_SESSION_INSTANCES, semaphoreName) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">If</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">If</span> (anotherInstanceRunningForUser) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Then</span> runAnotherDialogResult <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> MessageBox.Show(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Another
instance is already running. Do you want to run another?"</span>, _<br /><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Already
Running..."</span>, MessageBoxButtons.YesNo, MessageBoxIcon.Question) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">If</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
If this is the first instance of the application, or a further instance but the user
wants more than one...</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">If</span> (anotherInstanceRunningForUser <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">False</span>) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">Or</span> _
((anotherInstanceRunningForUser <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">True</span>) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">And</span> (runAnotherDialogResult <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> DialogResult.Yes)) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Then</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">'
Run the application</span> mainForm <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">New</span> Form1(mutexName)
Application.Run(mainForm) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">If</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Catch</span> ex <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">As</span> Exception <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">MsgBox</span>(ex.Message) <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">End</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">Try</span></span>
        </pre>
        <p>
I hope that mayhelp someone in the future and save them a day trawling through the
web sticking examples of code together and getting failed results like I did.
</p>
        <p>
Regards,<br />
Dib.
</p>
        <p>
 
</p>
        <font color="#000000" face="Courier New">
        </font>
        <img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=3c6c00f1-740c-4bf2-b6ec-3875ad339beb" />
      </body>
      <title>VB.Net Single Instance application on Terminal Server </title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,3c6c00f1-740c-4bf2-b6ec-3875ad339beb.aspx</guid>
      <link>http://www.duanewingett.info/2010/07/30/VBNetSingleInstanceApplicationOnTerminalServer.aspx</link>
      <pubDate>Fri, 30 Jul 2010 07:21:34 GMT</pubDate>
      <description>&lt;p&gt;
VB.Net Single Instance application on Terminal Server 
&lt;/p&gt;
&lt;p&gt;
Yesterday at work I spent nearly the whole day bashing my head against a wall trying
to replicate functionality that our original VB6 application had into the new .Net
conversion. The orginal VB6 application used&amp;nbsp;"&lt;strong&gt;App.PrevInstance&lt;/strong&gt;"
to determine if another instance was running or not. This appeared to work for multiple
users on Terminal Servers, so each user could run an instance of the app, but it would
warn if they tried to open another.
&lt;/p&gt;
&lt;p&gt;
VB.Net does not appear to have such direct functionality. Looking on the web provided
various 'solutions' to the problem. However each one seemed to have an 'issue' with
our scenario. By the afternoon I was looking at the &lt;strong&gt;Mutex&lt;/strong&gt; objects
which a lot of people seemed to find worked for them. However for me I was getting
an "&lt;span name="subject"&gt;Object synchronization method was called from an unsynchronized
block of code&lt;/span&gt;" error when closing the second instance onwards.
&lt;/p&gt;
&lt;p&gt;
Looking into the &lt;strong&gt;Mutex&lt;/strong&gt; object in a bit more depth it seemed that
maybe it was not the right object for our purpose but maybe the &lt;strong&gt;Semaphore&lt;/strong&gt; object
would be better.
&lt;/p&gt;
&lt;p&gt;
In the end the solution I used was to use a named Semaphore. When the application
first instance&amp;nbsp;runs it would attempt to open the named Semaphore and if it did
not exist, assume it was the first instance and create one. The second instance when
run would again look for and open the named Semaphore and if it exists and it manages
to open it then it would assmue it is a second instance of the application.
&lt;/p&gt;
&lt;p&gt;
By prefixing the Semaphorename with "Local\" it will allow each &lt;strong&gt;Terminal Server&lt;/strong&gt; session
to have it's own Semaphore so each remote user would not affected by another.
&lt;/p&gt;
&lt;p&gt;
The elements of the code I used are below.
&lt;/p&gt;
&lt;p&gt;
Imports:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Imports&lt;/span&gt; System.Threading&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Declarations:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Private&lt;/span&gt; SingleInstanceSemaphore &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; Semaphore &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Nothing&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
This needs to live for the life of the application&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Const&lt;/span&gt; MAX_SESSION_INSTANCES &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Integer&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 1 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Const&lt;/span&gt; SEMAPHORE_NAME &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;String&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"{9A49BB2C-45D2-4bb9-B38E-74F9DB612B96}"&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
Unique for each application&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Main Method:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'''
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'''
This is the main application entrance point.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'''
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Sub&lt;/span&gt; Main() &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
We need a name for the semaphore that is specific to to the Application / User combination&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
We prefix the semaphoreName with "Local\" to allow this to run under terminal services. &lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
The "Local\" prefix forces this into local user space. &lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
If we want to forbid this in TS, use the "Global\" prefix.&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Dim&lt;/span&gt; semaphorePrefix &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;String&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Local"&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
Or "Global" if required&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Dim&lt;/span&gt; semaphoreName &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;String&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;String&lt;/span&gt;.&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Format&lt;/span&gt;(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"{0}\{1}{2}"&lt;/span&gt;,
semaphorePrefix, SEMAPHORE_NAME, Environment.UserName) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Dim&lt;/span&gt; anotherInstanceRunningForUser &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Boolean&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;True&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Dim&lt;/span&gt; runAnotherDialogResult &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; DialogResult &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; DialogResult.No &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Dim&lt;/span&gt; mainForm &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; Form1 &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Nothing&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Try&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Try&lt;/span&gt; SingleInstanceSemaphore &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; Semaphore.OpenExisting(semaphoreName) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Catch&lt;/span&gt; ex &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; Exception
anotherInstanceRunningForUser &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;False&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Try&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;If&lt;/span&gt; (anotherInstanceRunningForUser &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;False&lt;/span&gt;) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Then&lt;/span&gt; SingleInstanceSemaphore &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;New&lt;/span&gt; Semaphore(0,
MAX_SESSION_INSTANCES, semaphoreName) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;If&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;If&lt;/span&gt; (anotherInstanceRunningForUser) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Then&lt;/span&gt; runAnotherDialogResult &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; MessageBox.Show(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Another
instance is already running. Do you want to run another?"&lt;/span&gt;, _&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Already
Running..."&lt;/span&gt;, MessageBoxButtons.YesNo, MessageBoxIcon.Question) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;If&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
If this is the first instance of the application, or a further instance but the user
wants more than one...&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;If&lt;/span&gt; (anotherInstanceRunningForUser &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;False&lt;/span&gt;) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;Or&lt;/span&gt; _
((anotherInstanceRunningForUser &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;True&lt;/span&gt;) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;And&lt;/span&gt; (runAnotherDialogResult &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; DialogResult.Yes)) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Then&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;'
Run the application&lt;/span&gt; mainForm &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;New&lt;/span&gt; Form1(mutexName)
Application.Run(mainForm) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;If&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Catch&lt;/span&gt; ex &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;As&lt;/span&gt; Exception &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;MsgBox&lt;/span&gt;(ex.Message) &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;End&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;Try&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
I hope that mayhelp someone in the future and save them a day trawling through the
web sticking examples of code together and getting failed results like I did.
&lt;/p&gt;
&lt;p&gt;
Regards,&lt;br&gt;
Dib.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;font color=#000000 face="Courier New"&gt;&lt;/font&gt;&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=3c6c00f1-740c-4bf2-b6ec-3875ad339beb" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,3c6c00f1-740c-4bf2-b6ec-3875ad339beb.aspx</comments>
      <category>.Net</category>
      <category>Mutex</category>
      <category>Semaphore</category>
      <category>Single Instance</category>
      <category>Terminal Server</category>
    </item>
    <item>
      <trackback:ping>http://www.duanewingett.info/Trackback.aspx?guid=3dbc6ea6-9e1c-42a5-a075-930d2c9ac0be</trackback:ping>
      <pingback:server>http://www.duanewingett.info/pingback.aspx</pingback:server>
      <pingback:target>http://www.duanewingett.info/PermaLink,guid,3dbc6ea6-9e1c-42a5-a075-930d2c9ac0be.aspx</pingback:target>
      <dc:creator>Duane Wingett</dc:creator>
      <wfw:comment>http://www.duanewingett.info/CommentView,guid,3dbc6ea6-9e1c-42a5-a075-930d2c9ac0be.aspx</wfw:comment>
      <wfw:commentRss>http://www.duanewingett.info/SyndicationService.asmx/GetEntryCommentsRss?guid=3dbc6ea6-9e1c-42a5-a075-930d2c9ac0be</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today I hit hit this error message while filling a typed DataSet Datatable. The odd
thing was I could preview the data in the DataSet designer and the data looked fine.
</p>
        <p>
I had to resort to Google and that returned this page, which if you hit this error,
I would definately recommend. Look specifically for Sanjeys post about six posts down.
</p>
        <p>
        </p>
        <p>
          <a href="http://weblogs.asp.net/rosherove/archive/2004/10/03/DataSet-hell-_2D00_-_2200_Failed-to-enable-constraints.-One-or-more-rows--contain-values_2E002E002E002E002200_.aspx" target="_blank">Roy
Osherove's Blog - Dataset Hell</a>
        </p>
        <img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=3dbc6ea6-9e1c-42a5-a075-930d2c9ac0be" />
      </body>
      <title>Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.</title>
      <guid isPermaLink="false">http://www.duanewingett.info/PermaLink,guid,3dbc6ea6-9e1c-42a5-a075-930d2c9ac0be.aspx</guid>
      <link>http://www.duanewingett.info/2010/06/08/FailedToEnableConstraintsOneOrMoreRowsContainValuesViolatingNonnullUniqueOrForeignkeyConstraints.aspx</link>
      <pubDate>Tue, 08 Jun 2010 18:35:03 GMT</pubDate>
      <description>&lt;p&gt;
Today I hit hit this error message while filling a typed DataSet Datatable. The odd
thing was I could preview the data in the DataSet designer and the data looked fine.
&lt;/p&gt;
&lt;p&gt;
I had to resort to Google and that returned this page, which if you hit this error,
I would definately recommend. Look specifically for Sanjeys post about six posts down.&lt;p&gt;
&lt;p&gt;
&lt;a href="http://weblogs.asp.net/rosherove/archive/2004/10/03/DataSet-hell-_2D00_-_2200_Failed-to-enable-constraints.-One-or-more-rows--contain-values_2E002E002E002E002200_.aspx" target="_blank"&gt;Roy
Osherove's Blog - Dataset Hell&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.duanewingett.info/aggbug.ashx?id=3dbc6ea6-9e1c-42a5-a075-930d2c9ac0be" /&gt;</description>
      <comments>http://www.duanewingett.info/CommentView,guid,3dbc6ea6-9e1c-42a5-a075-930d2c9ac0be.aspx</comments>
      <category>.Net</category>
      <category>Asp.Net</category>
      <category>C#</category>
      <category>Database</category>
      <category>Errors</category>
    </item>
  </channel>
</rss>
