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
Setting a Decimal field to Null in code
-
- Posts: 38
- Joined: Tue 07 Mar 2006 17:13
I used the following code with MySQLDirect .NET 3.55.20:
and it worked fine. Try to use this version too.
Code: Select all
Dim ParamRow As DataRow = MySqlDataTable1.NewRow()
ParamRow.Item("rebate_override") = DBNull.Value
MySqlDataTable1.Rows.Add(ParamRow)
MySqlDataTable1.Update()
-
- Posts: 38
- Joined: Tue 07 Mar 2006 17:13