Re: Check if an object is null

Tech-Archive recommends: Fix windows errors by optimizing your registry



I am using:

If MyObject.Equals(DBNull.Value) Then
....

Do you think this work?

At least I didn't have any problem in my code.

Thanks,
Miguel

Cowboy (Gregory A. Beamer) wrote:
In ASP.NEt 1.1 or in 2.0 without a nullable type, you would use DbNull.Value

if (x == DbNull.Value)
{
//is null
}

In 2.0, you have nullable types. I assume you are not using them however, or
are using VB.NET. In VB.NET 2.0, you use

Dim nullable1 As Nullable(Of DateTime) = New Nullable(Of DateTime)
If Not nullable1.HasValue Then
End If


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"shapper" <mdmoura@xxxxxxxxx> wrote in message
news:1160430331.365309.41920@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hello,

Inside a class I have 4 propertiy types:

1. String

2. Boolean

3. Mail.MailPriority

4. Mail.MailAddressCollection

I need to check if each property is null, i.e., if it wasn't defined
any value for them.

How can I do it?

I tried NULL but it got an error to use System.DBNull but I got error
again.

Thanks,

Miguel


.



Relevant Pages

  • Re: best practice for inserting rows using a dataAdapter?
    ... "Cowboy (Gregory A. Beamer)" wrote: ... nice perf gain by simply creating strongly typed datasets, ... Dim da As new SqlDataAdapter ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: best practice for inserting rows using a dataAdapter?
    ... "Cowboy (Gregory A. Beamer)" wrote: ... nice perf gain by simply creating strongly typed datasets, ... Dim da As new SqlDataAdapter ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: set Page.IsValid = false;
    ... actually by using server transfer, perhaps because i'm also using ajax, i ... "Cowboy (Gregory A. Beamer)" wrote: ... Cowboy is a name given to me when I moved to Georgia and still wore a cowboy ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: group dataset
    ... "type table" that shows luxury, ... CASE automobile WHEN 'Chevy' THEN 'Standard' ... "Cowboy (Gregory A. Beamer)" wrote: ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Recommend Community Software
    ... the other app within your full Sharepoint portal. ... modules that may encompass all the functionality you need. ... "Cowboy (Gregory A. Beamer)" wrote: ...
    (microsoft.public.dotnet.framework.aspnet)