Problem inserting into Access Database using VB.NET 4.0

I have been working on this for days trying to figure out why I am getting this error and can't find it.  I am trying to do an insert into my Access DB using a TableAdapter as shown below:
Me.NewEmployeeEmployerInfoTableAdapter.Insert(EEID,
                                                            drRowEmployees("EmployeeID"),
                                                            drRowEmployees("EmployerID"),
                                                            IIf(IsDBNull(drRowEmployees("DepartmentNumber")), "", drRowEmployees("DepartmentNumber")),
                                                            drRowEmployees("EmployeeType"),
                                                            drRowEmployees("EmployeeStatus"),
                                                            IIf(IsDBNull(drRowEmployees("HireDate")), dtDefault, drRowEmployees("HireDate")),
                                                            IIf(IsDBNull(drRowEmployees("TerminationDate")), dtDefault, drRowEmployees("TerminationDate")),
                                                            IIf(IsDBNull(drRowEmployees("EffectiveDateforLifeInsurance")), dtDefault, drRowEmployees("EffectiveDateforLifeInsurance")),
                                                            IIf(IsDBNull(drRowEmployees("LifeInsuranceFaceAmount")), decZero, CDec(drRowEmployees("LifeInsuranceFaceAmount"))),
                                                            IIf(IsDBNull(drRowEmployees("ActiveDateInPlan")), dtDefault, drRowEmployees("ActiveDateInPlan")),
                                                            drRowEmployees("PlanStatus"),
                                                            decZero,
                                                            IIf(IsDBNull(drRowEmployees("BenefitFormsRecevied")), dtDefault, drRowEmployees("BenefitFormsRecevied")),
                                                            IIf(IsDBNull(drRowEmployees("AccountValuation")), dtDefault, drRowEmployees("AccountValuation")),
                                                            IIf(IsDBNull(drRowEmployees("CheckWritten")), dtDefault, drRowEmployees("CheckWritten")),
                                                            IIf(IsDBNull(drRowEmployees("CheckNo")), "", drRowEmployees("CheckNo")),
                                                            decZero)

I am getting the following error and I can't figure out where the error is coming from:
Conversion from type 'DBNull' to type 'Decimal' is not valid.

The only variables that are defined as Decimal are being set to 0.0 using a variable defined as follows:  Dim decZero As Decimal = 0.0

Can someone tell me how to find out which field this is failing on?
dyaroshAsked:
Who is Participating?
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You might try String.IsNullOrEmpty instead:

IIf(String.IsNullOrEmpty(drRowEmployees("DepartmentNumber")), "", drRowEmployees("DepartmentNumber")),

Or if drRowEmployees is a DataRow, you can try the IsNull method:

IIF(drRowEmployees.IsNull("DepartmentNumber"), "TrueValue", "FalseValue")
0
 
NorieVBA ExpertCommented:
Have you tried replacing some of the expressions with hard-coded values?

Obviously that won't solve the problem, but might help find which field the problem is with.
0
 
dyaroshAuthor Commented:
I ended up using the String.IsNullOrEmpty and that fixed my problem.  Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.