error when using IsDbNull function on output parameter in code behind

Hi There,

I am trying to check if an output parameter IsDbNull, but I keep getting an error "Reference to a non-shared member requires an object reference."

if IsDbNull(myCommand.Parameters("@errmsg1").value) Then
     label1.text = "The parameter is null"
End if

What am I doing wrong?

Sean
LVL 5
bullroutAsked:
Who is Participating?
 
mmarinovConnect With a Mentor Commented:
so have you try

if myCommand.Parameters("@errmsg1").Value Is DbNull.Value Then

B..M
0
 
shovavnikCommented:
Try using uppercase property names:

myCommand.Parameters("@errmsg1").Value
0
 
shovavnikConnect With a Mentor Commented:
You can also try:

if myCommand.Parameters("@errmsg1").Value) = DbNull.Value Then
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
shovavnikCommented:
Last try:

if myCommand.Parameters("@errmsg1").Value) Is Nothing Then

I can't quite remember if the value is converted to a regular base type value or remains a db value.
0
 
mmarinovCommented:
Hi,

the correct answer is the second one
when a parameter is returned from the db it is not converted to Nothing but it is DBNull.Value

Regards,
B..M
0
 
bullroutAuthor Commented:
Hi There,

I keep getting an error saying "expected end of statment", what am I missing?

Sean

 if myCommand.Parameters("@errmsg1").Value) = DbNull.Value Then
            '*********************************************************
            'set the user role and make sure that they go to the correct
            ' place
            '*********************************************************

            strRoleName = myCommand.Parameters("@RoleName").value
            intUserID   = myCommand.Parameters("@UserID").value
            strUsername = myCommand.Parameters("@TheUsername").value
            
            Session("IsLoggedIn") = True
            Session("MemberID")   = intUserID
            Session("UserRole")   = strRoleName
            Session("UserName")   = strUsername
   
            If Session("UserRole") <> "Users" Then
                  response.redirect("adminmainmenu.aspx")
            Else
                  response.redirect("mainmenu.aspx")
            End if
      Else
            label1.text = myCommand.Parameters("@errmsg1").value
      End if
0
 
mmarinovCommented:
why do you have 2 closing brackets here
if myCommand.Parameters("@errmsg1").Value) = DbNull.Value Then

it should be

if myCommand.Parameters("@errmsg1").Value = DbNull.Value Then

B..M
0
 
bullroutAuthor Commented:
Hi There,

I did try this but then I get the following error "Operator '=' is not defined for types 'System.Object' and 'System.DBNull'. Use 'Is' operator to compare two reference types."

Sean
0
 
bullroutAuthor Commented:
damm, I tried "if myCommand.Parameters("@errmsg1").Value IsDbNull.Value Then"

cheers for the help, Sean
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.