Operator '=' is not defined for type 'Integer' and type 'DBNull'

The below code works until objComp3  has rows in it.

Then I get the error

Operator '=' is not defined for type 'Integer' and type 'DBNull'.

        While objComp3.Read()


            If objComp3("IVRECORDID") = DBNull.Value Then

                Session("IQAComplianceMode") = "Update"
                btnComplianceButton.Text = "Update Complance"

            Else



                Session("IQAComplianceMode") = "Insert"
                btnComplianceButton.Text = "Add Complance"



            End If
        End While

Open in new window

EdAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Which line raises the error?
0
AndyAinscowFreelance programmer / ConsultantCommented:
If objComp3("IVRECORDID") == DBNull.Value Then

a single = is an assignment, you need == to compare
0
Fernando SotoRetiredCommented:
Hi edjones1;

Try it like this.
If objComp3("IVRECORDID") Is DBNull.Value Then

Open in new window

0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Shaun KlineLead Software EngineerCommented:
If objComp3 is a SqlDataReader, use this:

objComp3.IsDBNull(objComp3.GetOrdinal("IVRECORDID"))
0
AndyAinscowFreelance programmer / ConsultantCommented:
Ahh, wrong language!!
0
Lokesh B RDeveloperCommented:
While objComp3.Read()
	If objComp3("IVRECORDID") Is Nothing AndAlso objComp3("IVRECORDID") = DBNull.Value Then
		Session("IQAComplianceMode") = "Update"
		btnComplianceButton.Text = "Update Complance"
	Else
		Session("IQAComplianceMode") = "Insert"
		btnComplianceButton.Text = "Add Complance"
	End If
End While

Open in new window

0
EdAuthor Commented:
Sorry I made somwe errors in what I posted.

Here's the code that does not work.

I just want it to do one thing if the recordset has rows and something else if it does not.

        While objComp3.Read()


            If objComp3("IVRECORDID") = DBNull.Value Then


                Session("IQAComplianceMode") = "Insert"
                btnComplianceButton.Text = "Add Complance"

                lbIVIDCompliance.Text = "There is currently no compliance record stored for IV ID - " + ivid.ToString

                lbIVIDCompliance.ForeColor = Color.DarkRed


            Else

                Session("IQAComplianceMode") = "Update"
                btnComplianceButton.Text = "Update Complance"


                lbIVIDCompliance.Text = "Update IV ID - " + ivid.ToString


            End If
        End While

Open in new window

0
EdAuthor Commented:
if objComp3 is empty I want to set the session to Insert  

If objComp3  in not empty then set the Session to Update
0
Lokesh B RDeveloperCommented:
Hi,

try this code

While objComp3.Read()
	If objComp3("IVRECORDID") IsNot Nothing AndAlso objComp3("IVRECORDID") <> DBNull.Value Then
		Session("IQAComplianceMode") = "Update"
		btnComplianceButton.Text = "Update Complance"
	Else
		Session("IQAComplianceMode") = "Insert"
		btnComplianceButton.Text = "Add Complance"
	End If
End While

Open in new window

0
EdAuthor Commented:
Lokesh B R

I have tried the code but nothing happens

btnComplianceButton.Text and Session("IQAComplianceMode")  is blank
0
CodeCruiserCommented:
Does this work?

One problem I can see is that you are setting same session variable and same button text in a loop. Are you only expecting one row in the reader?

        While objComp3.Read()
            If IsDBNull(objComp3("IVRECORDID")) Then
                Session("IQAComplianceMode") = "Insert"
                btnComplianceButton.Text = "Add Complance"
                lbIVIDCompliance.Text = "There is currently no compliance record stored for IV ID - " + ivid.ToString
                lbIVIDCompliance.ForeColor = Color.DarkRed
            Else
                Session("IQAComplianceMode") = "Update"
                btnComplianceButton.Text = "Update Complance"
                lbIVIDCompliance.Text = "Update IV ID - " + ivid.ToString
            End If
        End While

Open in new window

0
EdAuthor Commented:
CodeCruiser

I'm afraid that it does not work..

lbIVIDCompliance.Text  remains blank and the session gets set to neither INSERT OR UPDATE..


The dataset gets populated by this..

ALTER PROCEDURE [dbo].[GET_IQA_Compliance]


@IVRecordID int



AS



Select 
[TRAINEEID]
           ,[POT]
           ,[ADDEDBY]
           ,[IVRECORDID]
           ,[CREDITSCORRECT]
           ,[RULESCOMBINATIONCORRECT]
           ,[ILPINPLACE]
           ,[ILPUPTODATE]
           ,[HAVEPREVIOUSACTIONSCOMPLETED]
           ,[ISDELIVERYMODELINPLACE]
           ,[ISDELIVERYMODELUPTODATE]
From

[dbo].[I_IQA_COMPLIANCE]

where IVRECORDID = @IVRecordID

Open in new window

0
Lokesh B RDeveloperCommented:
Hi,

are you sure there are some rows for ID?

If objComp3.HasRows Then
      While objComp3.Read()
            If objComp3("IVRECORDID") IsNot Nothing AndAlso objComp3("IVRECORDID") <> DBNull.Value Then
                  Session("IQAComplianceMode") = "Update"
                  btnComplianceButton.Text = "Update Complance"
            Else
                  Session("IQAComplianceMode") = "Insert"
                  btnComplianceButton.Text = "Add Complance"
            End If
      End While
Else
      btnComplianceButton.Text = "NO ROWS FOUND"
End If
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EdAuthor Commented:
It was not getting the ID from

 GridIVRecs.SelectedDataKey.Value
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.