Solved

pass 0 integer value shows a null

Posted on 2011-03-08
8
319 Views
Last Modified: 2012-05-11
this is driving me crazy. and I had this problem before, and I fixed it, but I can't remember what I did.

I am giving a variable a value of 0, and when it inserts into the database it shows as null.

grrrrrrrrrrrrrrr

 
If Active = Nothing Then
            CmdSelect.Parameters.AddWithValue("@Active", DBNull.Value)
        Elseif 
            CmdSelect.Parameters.AddWithValue("@Active", Active)
        End If

Open in new window

0
Comment
Question by:TheWebGuy38
8 Comments
 

Author Comment

by:TheWebGuy38
Comment Utility
tried this, but did not help

 If Active = Nothing Then
            CmdSelect.Parameters.AddWithValue("@Active", DBNull.Value)
        ElseIf Active = "0" Or Active = "1" Then
            CmdSelect.Parameters.AddWithValue("@Active", Active)
        End If
     
0
 
LVL 22

Expert Comment

by:Snarf0001
Comment Utility
Try
If active is nothing
Instead of
If active = nothing
0
 

Author Comment

by:TheWebGuy38
Comment Utility
hrmmm,,, doesn't seem to like integer variables
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
Comment Utility
Try this:  (you had a ElseIf instead of a Else)

If Active = Nothing Then
    CmdSelect.Parameters.AddWithValue("@Active", DBNull.Value)
Else
    CmdSelect.Parameters.AddWithValue("@Active", Active)
End If

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:TheWebGuy38
Comment Utility
oh, that's how it originally was, I think I was trying to change it back and I missed the if
0
 
LVL 14

Expert Comment

by:dejaanbu
Comment Utility
When you trace, you get the value of Active is always 0 ?

did u check the stored procedure, whether any condition added there like that?

another pbm is, the meaning of Nothing is assigning default value .

ie., if we assign nothing to an integer, it will be taken as 0   ..see msdn documents..


so u have to handle this in different way
0
 
LVL 14

Expert Comment

by:dejaanbu
Comment Utility
u have to remove the if checking ..

because, even though the value of Active is 0 , it will be equal to nothing ...

instead you can do like this, If this suits ur needs

if Active>0 Then
CmdSelect.Parameters.AddWithValue("@Active", Active)
Else
CmdSelect.Parameters.AddWithValue("@Active", DBNull.Value)
End if

Open in new window

0
 
LVL 4

Expert Comment

by:fromer
Comment Utility

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Active As Integer
        Active = 0
        If Active = Nothing Then
            MessageBox.Show("True")
        Else
            MessageBox.Show("False")
        End If
    End Sub
End Class

This prints True... "Active = Nothing" returns true when Active = 0
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

13 Experts available now in Live!

Get 1:1 Help Now