Solved

error when using IsDbNull function on output parameter in code behind

Posted on 2004-08-24
9
850 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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