Results 1 to 9 of 9

Thread: [2005] is there a special VB/Access null value?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    257

    [2005] is there a special VB/Access null value?

    I remember something from college about there being some special null value that you have to use when writing to an Access database. Right now a bunch of text fields in the DB are Allow Zero Length: No. So when I try and send it this statement:

    INSERT INTO [DOG DATA] ([OWNER ID],BREED,SEX,[SEX ENTRY],[CALL NAME],[DATE OF BIRTH],[PLACE OF BIRTH],BREEDER,SIRE,DAM, [DOG HEIGHT],[NADAC REG NUM],[NADAC DOG HEIGHT],[NADAC MEASURED JUMP HEIGHT]) VALUES (379,'border collie','Female','2','Taka','02/14/2001','','','','',21,'07-04215',21,'16')

    it gives me an error about the value of those red ones being a zero length string. I'm using string variables to build the SQL statement's values right now. Is there some value I can assign them that it will accept like "NULL" or something? I recall using something like VBNULL or DBNULL or something a long time ago but nothing I've tried worked so far.
    I tried to end process on Visual Studio 2005
    but PETA stopped me saying it's smart enough
    to be a living creature

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2005] is there a special VB/Access null value?

    try
    vb Code:
    1. nothing

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2005] is there a special VB/Access null value?

    DBNull
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    257

    Re: [2005] is there a special VB/Access null value?

    If I use nothing doesn't that wipe it from memory completely and you can't use the variable after that? And DBNull sounds more familiar but do I just do somestringvar = DBNull?
    I tried to end process on Visual Studio 2005
    but PETA stopped me saying it's smart enough
    to be a living creature

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] is there a special VB/Access null value?

    If you're writing a null value as a literal in an SQL statement then it's just NULL, with no double or single quotes. If you are inserting a value into a parameter or field in VB code then you want the DBNull.Value property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    257

    Re: [2005] is there a special VB/Access null value?

    ohhhh I gotcha. Hopefully Access isn't too retarded to take NULL. I dunno if it'll still consider that a zero length string but I'll find out. I really, really don't want to write a dozen if statements that remove that field from the insert statement if they're blank so hopefully it will work
    I tried to end process on Visual Studio 2005
    but PETA stopped me saying it's smart enough
    to be a living creature

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] is there a special VB/Access null value?

    NULL is not a zero length string and vice versa. In VB, is an empty string the same as Nothing? No it's not. One is an object containing no characters and the other is no object at all. The same is true in databases.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    257

    Re: [2005] is there a special VB/Access null value?

    I'm pretty sure if I assigned a string variable nothing then appended it to my SQL statement string, it'd tear a hole in the universe. Either that or crash or append nothing. Either way, I addressed the little problem of needing single quotes when there is a value and needing them not there if it's null and now it works yay!
    I tried to end process on Visual Studio 2005
    but PETA stopped me saying it's smart enough
    to be a living creature

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] is there a special VB/Access null value?

    I did not say that you should assign Nothing anywhere. I was using the difference between Nothing and an empty string in VB to illustrate the difference between NULL and an empty string in a database. I already explained what you needed to do in post #5.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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