I’m coding a small app that inserts data into an access database, so far so good but i can’t seem to insert NULLs into the nullable fields.
I tried:
myAccessCommand.Parameters
.Add("@IDACCOMPAGNATEUR", OleDbType.Integer).Value =
(ActivityRegistration.id_invitee == 0
? DBNull.Value
: InviteeWebToSGM[ActivityRegistration.id_invitee]);
and
myAccessCommand.Parameters
.Add("@IDACCOMPAGNATEUR", OleDbType.Integer).Value =
(ActivityRegistration.id_invitee == 0
? (int?)null
: InviteeWebToSGM[ActivityRegistration.id_invitee]);
But both don’t work with different issues. My initial thought was to use DBNull.Value but it cannot be converted to anything near INT should it be INT or INT?. My second try works but returns an error message stating that there is no default value for my field but it does allow NULL. So my guess is that null in ADO.Net is not the same thing as DBNull.value…
Can anyone help me out?
IMO
DBNull.Valueis definitely the way to go.try