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?
 
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
 
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Fernando SotoRetiredCommented:
Hi edjones1;

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

Open in new window

0
 
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
 
EdAuthor Commented:
It was not getting the ID from

 GridIVRecs.SelectedDataKey.Value
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.