SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting error object cannot be cast from dbnull to other types.

    please help me to solve this error.
    in this line m getting error..m using c#.
    userType = Convert.ToInt16(oCmd.Parameters["SUSER_TYPE"].Value);

    here i want to check != System.DBNull.Value

    what to write for this...

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,868
    Mentioned
    37 Post(s)
    Tagged
    0 Thread(s)
    I do not see where you are trying to do the cast to throw that error.

    And where are you assigning the value from the db?

    You will have to check. If (var != DBNull.Value)

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NightStalker-DNS View Post
    I do not see where you are trying to do the cast to throw that error.

    And where are you assigning the value from the db?

    You will have to check. If (var != DBNull.Value)
    I got the solution

    userType = oCmd.Parameters["SUSER_TYPE"].Value;

    by removing the convert.toint16 and taking usertype datatype as object earlier i was taking datatype as int.

  4. #4
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,868
    Mentioned
    37 Post(s)
    Tagged
    0 Thread(s)
    ok. But for future note

    Convert.ToInt16 = short
    Convert.ToInt32 = int
    Convert.ToIng64 = long


Bookmarks

Posting Permissions

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