CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007
    Posts
    54

    Check on NULL with IsDbNull method

    Hallo,

    Met volgend statement wil ik enkele database field values ophalen,

    sSelect = "Select tnr_place,i_status, i_cancel_status,tnr_trip from tou_place

    using (OdbcCommand OCplace = new OdbcCommand(sSelect, SDBInfo.OcConnection))
    {
    OCplace.Parameters.Add("c_placeid", OdbcType.Text).Value = CCancel.cPlaceID.ToUpper();
    OdbcDataReader ODRplace = OCplace.ExecuteReader();
    if (!ODRplace.HasRows)
    {

    }
    else
    {
    CCancel.tnr_place = ODRplace.GetInt32(0);
    iStatus = ODRplace.GetInt32(1);

    --> I_STATUS_CANCEL kan een null value bevatten dus doe ik een
    check,

    if (!ODRplace.IsDBNull(2))
    {
    iCancelStatus = ODRplace.GetInt32(2) ;
    }

    }

    ODRplace.Close();
    }

    Wanneer I_STATUS_CANCEL = NULL --> alles in orde,

    Echter wanneer I_STATUS_CANCEL nu een waarde bevat vb 10, dan
    krijg ik volgende error melding "Specific cast not valid"
    op statement "iCancelStatus = ODRplace.GetInt32(2);".

    Wanneer ik statement eerst uitvoer gevolgd door test
    en dan opnieuw het statement dan lukt alles wel????

    iCancelStatus = ODRplace.GetInt32(2) ;
    if (!ODRplace.IsDBNull(2))
    {
    iCancelStatus = ODRplace.GetInt32(2) ;
    }

    Iemand een idee wat hiervan de oorzaak 'kan zijn?
    Mvg
    Last edited by Smetje; August 8th, 2008 at 07:30 AM.

  2. #2
    Join Date
    Jul 2007
    Posts
    54

    Re: Check on NULL with IsDbNull method

    Gevonden,

    Database veld is van het type small int en dus geen int,

    waarom dit wel werkt is me een raadsel?

    iCancelStatus = ODRplace.GetInt32(2) ;
    if (!ODRplace.IsDBNull(2))
    {
    iCancelStatus = ODRplace.GetInt32(2) ;
    }

  3. #3
    Join Date
    May 2003
    Location
    Germany
    Posts
    936

    Re: Check on NULL with IsDbNull method

    Can you repeat your questions in english?
    Useful or not? Rate my posting. Thanks.

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Check on NULL with IsDbNull method

    Try this:

    Code:
    object cancelStatusValue = ODRplace.GetValue(2) ;
    if (cancelStatusObject != null)
    {
        iCancelStatus = (int)cancelStatusValue;
    }
    And please use code tags in future (see link in my signature).

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured