Solved

error when using IsDbNull function on output parameter in code behind

Posted on 2004-08-24
9
848 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

11 Experts available now in Live!

Get 1:1 Help Now