parameterized sql...dbnull value?

Discussion in 'ASP .Net' started by darrel, Jul 3, 2006.

  1. darrel

    darrel Guest

    I should know this, but I don't...

    How do I enter a null value in an integer field using parameterized SQL?

    I have this:

    Dim bonding2ID As Integer
    If cleanSQLinput(DropDownList_bondingCo2.SelectedItem.Value.ToString) =
    "none" Then
    bonding2ID = DBNull.Value
    Else
    bonding2ID =
    cleanSQLinput(DropDownList_bondingCo2.SelectedItem.Value.ToString)
    End If

    But it's not liking the 'DBNull.Value' part.

    -Darrel

    =================================================================
    Win prizes searching google:
    http://www.blingo.com/friends?ref=hM72-GU3FWzMFnTqhv-2GE1FNtA
    darrel, Jul 3, 2006
    #1
    1. Advertising

  2. Hi,
    I think u r corret.

    Try System.DbNull.Value to store a NULL value.


    Regards,
    Bharti Kumar.


    darrel wrote:
    > I should know this, but I don't...
    >
    > How do I enter a null value in an integer field using parameterized SQL?
    >
    > I have this:
    >
    > Dim bonding2ID As Integer
    > If cleanSQLinput(DropDownList_bondingCo2.SelectedItem.Value.ToString) =
    > "none" Then
    > bonding2ID = DBNull.Value
    > Else
    > bonding2ID =
    > cleanSQLinput(DropDownList_bondingCo2.SelectedItem.Value.ToString)
    > End If
    >
    > But it's not liking the 'DBNull.Value' part.
    >
    > -Darrel
    >
    > =================================================================
    > Win prizes searching google:
    > http://www.blingo.com/friends?ref=hM72-GU3FWzMFnTqhv-2GE1FNtA
    Bharathi Kumar, Jul 4, 2006
    #2
    1. Advertising

  3. There's no easy way...you can use a nullable type in 2.0, but that only gets
    you 1/2 way there anyways.

    Write it as a method that returns an object *shrug*

    function GetBondId() as object
    if BLAH
    return DBNull.Value
    end if
    return cleanSQLinput(BLAHx)
    end function

    Karl

    --
    http://www.openmymind.net/



    "darrel" <> wrote in message
    news:...
    >I should know this, but I don't...
    >
    > How do I enter a null value in an integer field using parameterized SQL?
    >
    > I have this:
    >
    > Dim bonding2ID As Integer
    > If cleanSQLinput(DropDownList_bondingCo2.SelectedItem.Value.ToString) =
    > "none" Then
    > bonding2ID = DBNull.Value
    > Else
    > bonding2ID =
    > cleanSQLinput(DropDownList_bondingCo2.SelectedItem.Value.ToString)
    > End If
    >
    > But it's not liking the 'DBNull.Value' part.
    >
    > -Darrel
    >
    > =================================================================
    > Win prizes searching google:
    > http://www.blingo.com/friends?ref=hM72-GU3FWzMFnTqhv-2GE1FNtA
    >
    Karl Seguin [MVP], Jul 4, 2006
    #3
  4. his problem is assigning DBNull.Value to an integer...which you can't.

    Karl

    --
    http://www.openmymind.net/



    "Bharathi Kumar" <> wrote in message
    news:...
    > Hi,
    > I think u r corret.
    >
    > Try System.DbNull.Value to store a NULL value.
    >
    >
    > Regards,
    > Bharti Kumar.
    >
    >
    > darrel wrote:
    >> I should know this, but I don't...
    >>
    >> How do I enter a null value in an integer field using parameterized SQL?
    >>
    >> I have this:
    >>
    >> Dim bonding2ID As Integer
    >> If cleanSQLinput(DropDownList_bondingCo2.SelectedItem.Value.ToString) =
    >> "none" Then
    >> bonding2ID = DBNull.Value
    >> Else
    >> bonding2ID =
    >> cleanSQLinput(DropDownList_bondingCo2.SelectedItem.Value.ToString)
    >> End If
    >>
    >> But it's not liking the 'DBNull.Value' part.
    >>
    >> -Darrel
    >>
    >> =================================================================
    >> Win prizes searching google:
    >> http://www.blingo.com/friends?ref=hM72-GU3FWzMFnTqhv-2GE1FNtA

    >
    Karl Seguin [MVP], Jul 4, 2006
    #4
  5. darrel

    darrel Guest

    > There's no easy way...

    Damn.

    > function GetBondId() as object
    > if BLAH
    > return DBNull.Value
    > end if
    > return cleanSQLinput(BLAHx)
    > end function


    So, I'm basically just returning two different types of objects? I'll give
    that a shot.

    Out of curiosity, what kind of object DOES accept null values?

    -Darrel
    darrel, Jul 5, 2006
    #5
  6. System.Object is the only one I know about. Even Nullable types in 2.0 don't
    natively support a database's NULL value (which makes this pretty useless)

    Karl

    --
    http://www.openmymind.net/
    http://www.fuelindustries.com/


    "darrel" <> wrote in message
    news:...
    >> There's no easy way...

    >
    > Damn.
    >
    >> function GetBondId() as object
    >> if BLAH
    >> return DBNull.Value
    >> end if
    >> return cleanSQLinput(BLAHx)
    >> end function

    >
    > So, I'm basically just returning two different types of objects? I'll give
    > that a shot.
    >
    > Out of curiosity, what kind of object DOES accept null values?
    >
    > -Darrel
    >
    Karl Seguin [MVP], Jul 5, 2006
    #6
  7. darrel

    prasanth100

    Joined:
    Sep 5, 2010
    Messages:
    1
    Re : parameterized sql...dbnull value?

    Hi,
    Try to use DbNull.Value near parameter.It might work

    ex :
    if(txtName.Text != " ")
    {
    @Name,SqlDbType.VarChar
    }
    else
    {
    @Name,DBNull.Value
    }

    Try it out and see...
    prasanth100, Sep 5, 2010
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boris Zakharin

    Adding a DBNull value to the database

    Boris Zakharin, Aug 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    374
    Boris Zakharin
    Aug 27, 2003
  2. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    DBNull.Value Question

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Nov 4, 2004, in forum: ASP .Net
    Replies:
    11
    Views:
    12,791
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Nov 4, 2004
  3. Replies:
    10
    Views:
    2,637
    Alan Silver
    May 25, 2005
  4. darrel
    Replies:
    1
    Views:
    446
    Karl Seguin
    Dec 12, 2006
  5. Filip De Backer

    DBNull.Value and the dropdownlist

    Filip De Backer, Apr 15, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    309
    Brock Allen
    Apr 15, 2005
Loading...

Share This Page