Solved

pass 0 integer value shows a null

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

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…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

631 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