Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

pass 0 integer value shows a null

Posted on 2011-03-08
8
Medium Priority
?
326 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
[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
8 Comments
 

Author Comment

by:TheWebGuy38
ID: 35077034
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 23

Expert Comment

by:Snarf0001
ID: 35077293
Try
If active is nothing
Instead of
If active = nothing
0
 

Author Comment

by:TheWebGuy38
ID: 35077871
hrmmm,,, doesn't seem to like integer variables
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 35078268
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
 

Author Comment

by:TheWebGuy38
ID: 35078833
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
ID: 35082290
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
ID: 35082310
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
ID: 35083893

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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.…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

722 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