Results 1 to 9 of 9

Thread: quick question on UPDATE query

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    28

    quick question on UPDATE query

    If i want to set a text value in the database to null how should I pass that in the UPDATE Statement ?
    I tried these and didn't work --

    Update val = ' '
    Update val = NULL
    Update val as NULL
    Update val = "' '"

    This has been bugging me for the past few minutes so I appreciate if any one can show me the way. Thanks
    Regards --
    Vujjeni

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    DBnull.Value
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    28
    DOES'T seem to work...
    Is this how to do it ?

    set DBNull.columnName
    Regards --
    Vujjeni

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try UPDATE val IS NULL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    28
    Nope...IS NULL doesn't work either


    I guess I will use
    Set Val = ' '

    then trim the space out when I load the table values into my program.
    Thanks
    Regards --
    Vujjeni

  6. #6
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    here's my Update query...txtVendor.Text can have a NULL and it gets updated fine.


    VB Code:
    1. sqlcmd = "update pcms.pcms_pcard_transaction_header set vendor_name=?, transaction_amt=?, sales_tax_amt=?, updated_by=?,updated_date=? where trans_seq_no=" & sFirstCell
    2.             Dim objCommand As New OleDbCommand(sqlcmd, objCon)
    3.             objCommand.Parameters.Add("@vendor_name", System.Data.OleDb.OleDbType.Char, 42).Value = txtVendor.Text

    then when I go to populate my textboxes on my form, I do a NULL check...

    VB Code:
    1. If (objDR("vendor_name")) Is DBNull.Value Then
    2.    txtVendor.Text = String.Empty
    3.   Else : txtVendor.Text = (objDR("vendor_name"))
    4.  End If

    HTH....
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  7. #7
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    You could put in a Chr(0) as the value. Chr(0) returns a null equivelant.
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  8. #8
    Member
    Join Date
    Jan 2003
    Location
    Beer City
    Posts
    33
    isn't it

    myparam=nothing

    thats what I use

    tal
    its called the "F1" key-- use it

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by vujjeni
    DOES'T seem to work...
    Is this how to do it ?
    set DBNull.columnName
    Set keyword is no longer used in VB.NET . A workaround is to set the field in the database itself to accept null values . This works well all the time .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width