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

  • Question

  • Hi,

    I am getting ;Conversion from type 'DBNull' to type 'Double' is not valid when i try to update an SQL 2000 table.

      Dim fst As Double = DGV.Rows(i).Cells(5).Value
    

    the above code gets the value  and psses to a paramere in SP

    The table  datatype is smallmonay,  if fst has a value  it works  but when it has no value  it gives me the above error.

    How do i fix this/

     

    Thanks

    Tuesday, August 2, 2011 3:43 PM

Answers

  • Take a look if this article may be of help http://vbnotebookfor.net/2007/09/27/introduction-to-nullable-types-in-vbnet/ and you can check more links if you google on 'Nullable types VB.NET'
    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Wednesday, August 3, 2011 3:15 PM
    Moderator
  • if you did put the full code probably i could help

    any way as i said before you should not Fill it with null. you can use a query that fix the value you get from the database (like i wrote before isnull and so on...) or you can fix it before the fill action on the asp.net

    you can make you own function to fill in the grid like dont use :
    <%# Eval("JobId") %>
    but use:
    <%# YourFunc("JobId") %>

    and on the code file build the function

    ** and again if you will upload the project it will be easier to help

    Monday, August 8, 2011 5:04 PM
    Moderator

All replies

  • Please check this http://forums.asp.net/t/1441834.aspx

    http://uk.linkedin.com/in/ramjaddu
    Tuesday, August 2, 2011 3:48 PM
  • ramjaddu i checked te link you posted but no solution to my problem there,

     

    Wednesday, August 3, 2011 8:20 AM
  • where is your code ?

    how do ypou fill the DGV object?

    * you should not Fill it with null. if you are using query like: select x from y, then use "isnull" like this:

    for string:
    select isnull(x,'') from Y

    or if it is number field use:
    select isnull(x,0) from Y



    Wednesday, August 3, 2011 10:50 AM
    Moderator
  • Problem is that the double type doesn allow null. So you should first check if the value is null.
    Dim fst As Double 
    If DGV.Rows(i).Cells(5).Value
     Is DBNull.Value Then
    fst=<some default value??>
    Else
    fst=DGV.Rows(i).Cells(5).Value
    End If


    Another problem is that this is more of a VB question...

     

     

    Wednesday, August 3, 2011 10:55 AM
  • well i have tryed the is else but evan then it gave me an error: Conversion from string to money is not valid.....

     

    the fst value is ""  so it tryes to convert "" into money then it geves me the error

     

     

    Wednesday, August 3, 2011 3:04 PM
  • pituach i dont need to display 0, i need to have the cell i Datagridview empty.

    Wednesday, August 3, 2011 3:12 PM
  • Take a look if this article may be of help http://vbnotebookfor.net/2007/09/27/introduction-to-nullable-types-in-vbnet/ and you can check more links if you google on 'Nullable types VB.NET'
    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog
    Wednesday, August 3, 2011 3:15 PM
    Moderator
  • Any progress?
    Kalman Toth, SQL Server & Business Intelligence Training; sqlusa.com
    Monday, August 8, 2011 4:27 PM
    Moderator
  • if you did put the full code probably i could help

    any way as i said before you should not Fill it with null. you can use a query that fix the value you get from the database (like i wrote before isnull and so on...) or you can fix it before the fill action on the asp.net

    you can make you own function to fill in the grid like dont use :
    <%# Eval("JobId") %>
    but use:
    <%# YourFunc("JobId") %>

    and on the code file build the function

    ** and again if you will upload the project it will be easier to help

    Monday, August 8, 2011 5:04 PM
    Moderator