Setting a Decimal field to Null in code

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
[email protected]
Posts: 38
Joined: Tue 07 Mar 2006 17:13

Setting a Decimal field to Null in code

Post by [email protected] » 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

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Mon 19 Feb 2007 08:23

I used the following code with MySQLDirect .NET 3.55.20:

Code: Select all

        Dim ParamRow As DataRow = MySqlDataTable1.NewRow()
        ParamRow.Item("rebate_override") = DBNull.Value
        MySqlDataTable1.Rows.Add(ParamRow)
        MySqlDataTable1.Update()
and it worked fine. Try to use this version too.

[email protected]
Posts: 38
Joined: Tue 07 Mar 2006 17:13

Post by [email protected] » Tue 20 Feb 2007 21:55

Alexey,

Upgrading to the current version fixed my problem. Many thanks for the advice.

John

Alexey
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Post by Alexey » Wed 21 Feb 2007 07:02

You are welcome.

Post Reply