DBNULL Error

  • Thread starter Thread starter MadCrazyNewbie
  • Start date Start date
M

MadCrazyNewbie

Hey Group,

I keep getting this Error:

An unhandled exception of type 'System.ArgumentException' occurred in
system.data.dll
Additional information: "Cannot set Column 'SitesID' to be null. Please use
DBNull instead."

On the following line of code:

dsFax.Faxs.Rows(Me.BindingContext(dsFax, "Faxs").Position).Item("SitesID") =
Me.cboFaxsDepartment.SelectedValue

Anybody got any ideas or can point me in the right direction?

Many Thanks
MCN
 
From the information you provided I would say that either you have no value
in the Me.cboFaxsDepartment.SelectedValue

check with:
MsgBox(Me.cboFaxsDepartment.SelectedValue

OR... something goes wrong when you save and you don't get a value for the
SitesID column.

Are you allowed to insert Null in "SitesID" column? in that case and if you
WANT TO insert a null value, then you better use DBNull

/Lars
 
If Me.cboFaxsDepartment.SelectedValue Is Nothing Then
'you could also throw an exception or warning box instead of putting in DB
NULL
dsFax.Faxs.Rows(Me.BindingContext(dsFax, "Faxs").Position).Item("SitesID")
=
DbNull.Value
Else
dsFax.Faxs.Rows(Me.BindingContext(dsFax, "Faxs").Position).Item("SitesID")
=
Me.cboFaxsDepartment.SelectedValue
End If
 
Back
Top