Results 1 to 5 of 5

Thread: Send a null value to a database (conditional)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Send a null value to a database (conditional)

    How I do I send an actual null value to an SQL database? Right now I am sending a empty string but I have to change that to a null. I thought something like this would work but I must be missing something.
    VB Code:
    1. Dim strCityTax As String
    2.  
    3.         If txtCityTax.Text = "" Then
    4.             strCityTax = DBNull
    5.         Else
    6.             strCityTax = txtCityTax.Text
    7.         End If
    That puts a squiggly line under the DBNull with this warning: 'DBNull' is a type and cannot be used as an expression.

  2. #2
    Junior Member
    Join Date
    Apr 2004
    Posts
    19
    the db needs to be able to accept nulls, then send vbNullString
    www.mod2software.com
    Home of the VB.NET Class Builder Utility - Demo and Full versions available now!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354
    CattleRustler does that send an emtpy string? I ask because when I go to the field in the database I am not getting the <NULL> to show that the field is indeed null. I get the same type of behavior that I would with an empty string.

  4. #4
    Junior Member
    Join Date
    Apr 2004
    Posts
    19
    what I mean is the field in the db needs to be set to accept null values, then you can send vbNullString from code. If field is set not to accept nulls then you should be able to send "" empty string because it is not theoretically null. Different db's and programming languages may each handle this differently.
    www.mod2software.com
    Home of the VB.NET Class Builder Utility - Demo and Full versions available now!

  5. #5
    Hyperactive Member
    Join Date
    Feb 2001
    Location
    Houston, TX
    Posts
    342
    Try this..
    Code:
    strCityTax = DBNull.Value
    HTH

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