pass DBNull.Value as paramter of type object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John A Grandy

    pass DBNull.Value as paramter of type object

    I would like to pass a DataRow column value to a method that accepts an
    object parameter :

    MyMethod( object value ) {}


    However, a problem occurs if the column value is DBNull.Value

    MyMethod( DataRow["MyCol"] );


    A null reference exception is thrown in this case.

    What is the reason that a DBNull.Value can't be passed as a parameter of
    type object ?


  • Marc Gravell

    #2
    Re: pass DBNull.Value as paramter of type object

    MyMethod( DataRow["MyCol"] );

    It can.
    Are you sure that DataRow is non null and that the column is spelt
    correctly? Other than that, the bug is in some of the code not shown.

    Marc

    Comment

    Working...