Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Answered check column value for null vb

  • Sunday, March 11, 2012 7:04 PM
     
     

    hi 

    i'm working with a database application and i want to check if there is a null value in a specific column but it works only when its not null but if its null it throws an exception automatically 

    i tried to change the nullvalue property of this column but i'm not able it shows a message that its not a valid property

    i tried to change the source code in the code editer but it changes back automatically

All Replies

  • Sunday, March 11, 2012 7:19 PM
     
     

    Hello jacob gold,

    hi

    i'm working with a database application and i want to check if there is a null value in a specific column but it works only when its not null but if its null it throws an exception automatically

    i tried to change the nullvalue property of this column but i'm not able it shows a message that its not a valid property

    i tried to change the source code in the code editer but it changes back automatically

    what code you use to enhance and control the value of the column?
    You can also include the verification code within a try / catch and handle the exception inside the catch block associated with the text, relative to an invalid format.

    Regards.


  • Sunday, March 11, 2012 8:33 PM
     
     

     i created a tableadapter in the dataset with the designer to populate the datatable and then

    i used these code

    Dim billtable As New shullaccountDataSet.billDataTable

    billtbladatr.FillBy1(billtable, actionid)

                

    If IsDBNull(billtable.Item(0).billaliyaid) = True Then

    and the exception happens in the code that is generated by the application

     Public Property billaliyaid() As Integer
                Get
                    Try
                        Return CType(Me(Me.tablebill.billaliyaidColumn), Integer)
                    Catch e As Global.System.InvalidCastException
                        Throw New Global.System.Data.StrongTypingException("The value for column 'billaliyaid' in table 'bill' is DBNull.", e)
                    End Try
                End Get  

    i tried to change the code  but i'm not able to


  • Sunday, March 11, 2012 9:44 PM
     
     Proposed

    If you are using a typed dataset, which you appear to be, then the designer will have created a function for each table column called IsColumnNameNull.  Call that function before you try and use the value.

    • Proposed As Answer by Armin Zingler Sunday, March 11, 2012 9:55 PM
    •  
  • Monday, March 12, 2012 12:21 AM
     
     
    yes i use a typed dataset and i use this function but if the value is null it throws an exception and i can't change this function
  • Monday, March 12, 2012 12:33 AM
     
     
    yes i use a typed dataset and i use this function but if the value is null it throws an exception and i can't change this function
    The IsColumnNameNull does not throw an exception because it's the purpose of the function to check for Null. It can be named IsbillaliyaidNull or similar, but you'd see it yourself if you just type "billtable.Is" and have intellisense list the members starting with "Is"

    Armin

  • Monday, March 12, 2012 1:02 AM
     
     Answered

    If you are talking about the code you posted above then that is not the function I am referring to.

    In your typed dataset you have a billDataTable class.  You will also have a billRow class.  billaliyaid is a column in that table and there should be a function called IsbillaliyaidNull in the billRow class.  That is the function you should be calling - it cannot generate an exception.  Your code should probably look something like:

    If billtable(0).IsbillaliyaidNull then

    • Marked As Answer by jacob gold Monday, March 12, 2012 3:48 PM
    •  
  • Monday, March 12, 2012 3:49 PM
     
     
    thank you very much David i tried it  and it works perfect