none
Conversion from type 'DBNull' to type 'String' is not valid. RRS feed

  • Question

  • Hello
    I had put the data from staging database to the destination Db in the same instance. the data in the staging is coming from the excel sheet. There are some null values but the application which is connecting to the destination Db is giving the following error: 
    Conversion from type 'DBNull' to type 'String' is not valid
    So do i need the to update these Null values in the table. If yes then hoe should i do that. Would you give some query to do that. Or do i am thinking wrong way. 
    Please suggest me the solution.
    Thanks In advance

    Fighttillend_DBA/DEV
    Monday, May 2, 2011 2:41 PM

Answers

  • Instead of updating nulls with 0, you can update your select query using ISNULL.

    Select ISNULL(Col1,0) as IntCol, ISNULL(Col2,'') as VarcharCol From Table
    

     


    Amit Govil(amit.govil@hotmail.com)
    • Marked as answer by KJian_ Monday, May 9, 2011 3:24 AM
    Tuesday, May 3, 2011 4:57 AM

All replies

  • Can you show your current code? May be you just need to declare a nullable string, e.g. string?
    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Monday, May 2, 2011 2:42 PM
    Moderator
  • naomi 

    Sorry i did not get that what code you are talking about?

    Thanks


    Fighttillend_DBA/DEV
    Monday, May 2, 2011 2:49 PM
  • The error message you specified sometimes comes from .NET application, so that's why I thought you can show your .NET code.

    Also, make sure the destination table has all columns set as NULLable (for now).


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    Monday, May 2, 2011 2:51 PM
    Moderator
  • Actually i do not have the .net code its a VB code and i do not have the application installed on my machine.

    Just tell me the fix i will have something to explain to my team . So just tell me technical fix.

    Thanks


    Fighttillend_DBA/DEV
    Monday, May 2, 2011 3:12 PM
  • For now I think the solution will be in ensuring that all columns are nullable in the destination table. I can not 100% guarantee it will fix the error - you may need to find the source code if it will not.
    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Monday, May 2, 2011 3:17 PM
    Moderator
  • Ye s all the columns at destination which have the nulls are having NULL property.

    By source code mean the front end VB code for that screen?

    If yes i will try to get it from the developers wait for some minutes i will come up with code.

    Thanks

     

     


    Fighttillend_DBA/DEV
    Monday, May 2, 2011 3:27 PM
  • This error "conversion from type 'DBNULL' to type 'String' is not valid" normally comes at the front end only when you are either compairing some value with string or assigning a null to a string. 

    Apply a check of DBNULL

     

    If NOT YourStingValue IS DBNULL.Value Then
    .
    .
    .
    .
    .
    END IF
    
     or you can use Convert.ToString() as well


    Amit Govil(amit.govil@hotmail.com)
    Monday, May 2, 2011 7:19 PM
  • Friends 

    Sorry  

    I am more a backend person so what i did from my side was updated all the nulls with the 0 in table and waiting for the response from users. 

    will that work i do not know anything regarding the VB code

    i will update the result soon.

    Thanks


    Fighttillend_DBA/DEV
    Monday, May 2, 2011 8:30 PM
  • Instead of updating nulls with 0, you can update your select query using ISNULL.

    Select ISNULL(Col1,0) as IntCol, ISNULL(Col2,'') as VarcharCol From Table
    

     


    Amit Govil(amit.govil@hotmail.com)
    • Marked as answer by KJian_ Monday, May 9, 2011 3:24 AM
    Tuesday, May 3, 2011 4:57 AM