Advertisement
ASP_Volume2 String Manipulation #43483

Quick tip on how to handle NULL in ADO.net

If you're an old ADO programmer, you may be frustrated by not knowing exactly how to check for NULL. Here's a 1 second tip on how to do it in ADO.NET.

AI

Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Zdrojový kód
original-source
<p>If you try the old fashioned way of checking for null:</p>
<p>&nbsp;&nbsp;&nbsp; If IsNull(rsCompany(&quot;Name&quot;)) Then</p>
<p>Visual Studio will tell you that IsNull is not supported and to use DBNull 
instead.&nbsp; At first I thought this was really nice.&nbsp; However, when I 
tried to do:</p>
<p>&nbsp;&nbsp;&nbsp; If rscompany(&quot;Name&quot;) = DBNull Then</p>
<p>I got an error about assignments not allowed to a type!&nbsp; What was I to 
do?</p>
<p>The Visual Studio help was its usual cryptic self (&quot;The DBNull class is for 
handling NULL values&quot;...accurate by not alot of help).&nbsp; After some fumbling 
around, I stumbled on the answer, and thought I'd share it to hopefully save 
someone 5 minutes of having to research it:<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp; If rsCompany(&quot;Name&quot;) is DBNull.Value then</p>
<p>Hope this saves you some time!</p>
<p>&nbsp;</p>
Původní komentáře (3)
Obnoveno z Wayback Machine