Solved

pass 0 integer value shows a null

Posted on 2011-03-08
8
321 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
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 22

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

Accepted Solution

by:
wdosanjos earned 500 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
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.

 

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

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

24 Experts available now in Live!

Get 1:1 Help Now