DBNULL Error

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
 
L

Lars Netzel

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
 
A

Alex Papadimoulis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Null & DBNULL Problems 4
Data Error 20
Ado - Driving me Nuts 4
Error on Dbnull and integers 6
ASPNet Web - DBNull 3
Another Datagrid thing 1
sqlconnection question 2
Dataset problem 2

Top