Solved

error when using IsDbNull function on output parameter in code behind

Posted on 2004-08-24
9
854 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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
 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

623 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