Solved

error when using IsDbNull function on output parameter in code behind

Posted on 2004-08-24
9
847 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:bullrout
  • 3
  • 3
  • 3
9 Comments
 
LVL 8

Expert Comment

by:shovavnik
ID: 11889676
Try using uppercase property names:

myCommand.Parameters("@errmsg1").Value
0
 
LVL 8

Assisted Solution

by:shovavnik
shovavnik earned 100 total points
ID: 11889682
You can also try:

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

Expert Comment

by:shovavnik
ID: 11889690
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 11889716
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 5

Author Comment

by:bullrout
ID: 11889881
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
 
LVL 28

Expert Comment

by:mmarinov
ID: 11889896
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
 
LVL 5

Author Comment

by:bullrout
ID: 11889920
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
 
LVL 28

Accepted Solution

by:
mmarinov earned 400 total points
ID: 11889975
so have you try

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

B..M
0
 
LVL 5

Author Comment

by:bullrout
ID: 11890015
damm, I tried "if myCommand.Parameters("@errmsg1").Value IsDbNull.Value Then"

cheers for the help, Sean
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now