converting to dbnull

  • Thread starter Thread starter Tina
  • Start date Start date
T

Tina

I have instantiated an insertRow for a dataset. I now want to make the
GLCode DBNull.

I have tried:
insertRow.GLCode = Convert.dbnull
insertRow.GLCode = Convert.dbnull(insertRow.GLCode)

and several other things.

How is it done?
 
I tried that too: Value of type "System.dbnull" cannot be converted to
'String'
is the compile error.
T
 
Oh, I'm sorry. I didn't think long enough about what you wrote.

You are working with a typed dataset, so there is some "automagic" code
generation done for you to allow those columns to be strongly typed. That
works great when the columns aren't nullable. Unfortunately, they don't
deal well with DBNull values. Annoying, huh?

You can do this instead:

insertRow["GLCode"] = System.DBNull.Value;

Thus, you are using the string-based array indexer to get a reference to
the column in question. This is a feature of the DataRow class which is a
base class of your row's class, so this capability is inherited. It's
perfectly happy with DBNull.Value.

Cheers!

--JV
 
Yes, that worked just fine. Interesting issue.
Thanks,
T

JV said:
Oh, I'm sorry. I didn't think long enough about what you wrote.

You are working with a typed dataset, so there is some "automagic" code
generation done for you to allow those columns to be strongly typed. That
works great when the columns aren't nullable. Unfortunately, they don't
deal well with DBNull values. Annoying, huh?

You can do this instead:

insertRow["GLCode"] = System.DBNull.Value;

Thus, you are using the string-based array indexer to get a reference to
the column in question. This is a feature of the DataRow class which is a
base class of your row's class, so this capability is inherited. It's
perfectly happy with DBNull.Value.

Cheers!

--JV


Tina said:
I tried that too: Value of type "System.dbnull" cannot be converted to
'String'
is the compile error.
T
 
Back
Top