pass DBNull.Value as paramter of type object

J

John A Grandy

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 ?
 
M

Marc Gravell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top