Solved

pass 0 integer value shows a null

Posted on 2011-03-08
8
323 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 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