Link to home
Start Free TrialLog in
Avatar of Ed
EdFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of kaufmed
kaufmed
Flag of United States of America image

Which line raises the error?
If objComp3("IVRECORDID") == DBNull.Value Then

a single = is an assignment, you need == to compare
Hi edjones1;

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

Open in new window

If objComp3 is a SqlDataReader, use this:

objComp3.IsDBNull(objComp3.GetOrdinal("IVRECORDID"))
Ahh, wrong language!!
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

Avatar of Ed

ASKER

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

Avatar of Ed

ASKER

if objComp3 is empty I want to set the session to Insert  

If objComp3  in not empty then set the Session to Update
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

Avatar of Ed

ASKER

Lokesh B R

I have tried the code but nothing happens

btnComplianceButton.Text and Session("IQAComplianceMode")  is blank
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

Avatar of Ed

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of Lokesh B R
Lokesh B R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ed

ASKER

It was not getting the ID from

 GridIVRecs.SelectedDataKey.Value