Unable to set a colum to null

Posts   
 
    
ylockhead
User
Posts: 2
Joined: 02-Nov-2005
# Posted on: 02-Nov-2005 15:15:40   

I am trying to save a null value back to a table but I get an error. The error that I get is :"The value is of type 'System.DBNull' while the field is of type 'System.Int32'"

Here's my code:

'create entity enHearing = New DAL.EntityClasses.PM_PER_DIEM_HEARING_STGEntity(iHearingD)

'set the member_id column to null enHearing.SetNewFieldValue("MEMBER_ID", DBNull.Value)

The error occurs when I set the member_id to null. The column MEMBER_ID in my table is a Number(5) and there is no "Not Null" constraint on the column.

How can I set the member_id column to null? Thanks.

ylockhead
User
Posts: 2
Joined: 02-Nov-2005
# Posted on: 02-Nov-2005 15:41:03   

I figured it out. I needed to set it to Nothing instead of DBNull.Value because the column is numeric.

'set the member_id column to null enHearing.SetNewFieldValue("MEMBER_ID", Nothing)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 02-Nov-2005 15:44:13   

That's indeed a per-provider specific setting. Some providers (DB types) don't support DBNull.Value to be passed as a parameter value, others do.

Frans Bouma | Lead developer LLBLGen Pro
Aidan
User
Posts: 8
Joined: 20-Mar-2006
# Posted on: 20-Mar-2006 18:21:05   

Otis wrote:

That's indeed a per-provider specific setting. Some providers (DB types) don't support DBNull.Value to be passed as a parameter value, others do.

that solves my problem

Many Thanks !!!!

Aidan