Setting a Decimal field to Null in code
Posted: Fri 16 Feb 2007 21:36
I have a table and in it is a field called rebate_override, defined as follows:
`rebate_override` decimal(10,5) default NULL
Every day, I do a comparison of everything in this table against another table which has an interest rate in it. If a value exists in the second table, I write that value to 'rebate_override'. If there is no value in the second table, I want to set 'rebate_override' back to a Null value if it had a value the previous day.
I had the following in my code:
ParamRow.Item("rebate_override") = DBNull.Value
But I've discovered that this is not actually setting the value in the field to Null, but rather to Zero. In looking through the .NET documentation, it suggested the following:
Dim FullRebate As Nullable(Of Decimal)
FullRebate = Nothing
ParamRow.Item("rebate_override") = FullRebate
But that code throws an error saying Null isn't allowed, use DBNull instead.
I'm using VB 2005, and Corelab 3.50.10.0 (Runtime v2.0.50727), and MySQL Server 5.0.18-nt, fyi.
Any suggestions you could offer would be greatly appreciated.
Thanks,
John
`rebate_override` decimal(10,5) default NULL
Every day, I do a comparison of everything in this table against another table which has an interest rate in it. If a value exists in the second table, I write that value to 'rebate_override'. If there is no value in the second table, I want to set 'rebate_override' back to a Null value if it had a value the previous day.
I had the following in my code:
ParamRow.Item("rebate_override") = DBNull.Value
But I've discovered that this is not actually setting the value in the field to Null, but rather to Zero. In looking through the .NET documentation, it suggested the following:
Dim FullRebate As Nullable(Of Decimal)
FullRebate = Nothing
ParamRow.Item("rebate_override") = FullRebate
But that code throws an error saying Null isn't allowed, use DBNull instead.
I'm using VB 2005, and Corelab 3.50.10.0 (Runtime v2.0.50727), and MySQL Server 5.0.18-nt, fyi.
Any suggestions you could offer would be greatly appreciated.
Thanks,
John