Results 1 to 14 of 14

Thread: Record changes to NULL??

  1. #1

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    Record changes to NULL??

    I am running this query to a SQL Server database using ADO 2.5
    SELECT * FROM SkillValues WHERE ApplicationID=9 AND SkillID=3
    Which gives me this record
    mCertification = rs.Fields("Certification")
    mYearsExp = rs.Fields("YearsExp")
    mMonthsExp = rs.Fields("MonthsExp")

    The problem is when mCertification takes the value from rs.Fields("Certification") it changes to NULL. If I put a break point on mCertification = rs.Fields("Certification") and hover my mouse over rs.Fields("Certification"), it tells me the value is "any" which is the string value in the database, so far everything is good. But when I hit F8 to actually give that value to mCertification, I get an error saying "Invalid use of NULL". When I click debug and hover over rs.Fields("Certification") is now says the value is NULL. Any ideas?
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    When using F8, the value is set on the next line. So it sound like you do infact have a Null value in that Field.

    There are a few soulutions, on way is to use IIF Function, like:
    VB Code:
    1. mCertification =  IIF(rs.Fields("Certification").Value = Null, "", rs.Fields("Certification").Value)

    There has been discussion about using IIF, so do a seacrh and find whats best for you.




    Bruce.

  3. #3

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    I tried using the IIF, but I got an error there too. I just tried
    mCertification = IIf(rs.Fields("Certification") = Null, "", rs.Fields("Certification")) and got Invalid use of NULL and I tried
    mCertification = IIf(IsNull(rs.Fields("Certification")), "", rs.Fields("Certification")) and the same thing
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Does this work (temp substitution):
    VB Code:
    1. MsgBox  IIF(rs.Fields("Certification").Value = Null, "", rs.Fields("Certification").Value)

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by Bruce Fox
    Does this work (temp substitution):
    VB Code:
    1. MsgBox  IIF(rs.Fields("Certification").Value = Null, "", rs.Fields("Certification").Value)
    You will keep getting the Invalid use of Null error, because all statements are evaluated, no matter what IIf is going to use.

    Try
    VB Code:
    1. mCertification = rs.Fields("Certification") & ""

    or if its a numeric field
    VB Code:
    1. mCertification = Val("0" & rs.Fields("Certification"))
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  6. #6

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Same error. It is really stange here, because if I hover over it once I get the value "any", but if I hover again I get NULL. This is so damn stange. Here is what I get from teh DB running the query in QueryAnalyzer:

    SELECT * FROM EZapplication_SkillValuesTemp WHERE ApplicationID=9 AND SkillID=1

    SkillValueID=252
    ApplicationID=9
    SkillID=1
    YearsExp=10
    MonthsExp=1
    Certification=any
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by blindlizard
    Same error. It is really stange here, because if I hover over it once I get the value "any", but if I hover again I get NULL. This is so damn stange. Here is what I get from teh DB running the query in QueryAnalyzer:

    SELECT * FROM EZapplication_SkillValuesTemp WHERE ApplicationID=9 AND SkillID=1

    SkillValueID=252
    ApplicationID=9
    SkillID=1
    YearsExp=10
    MonthsExp=1
    Certification=any
    What kind of cursor are you using? ForwardOnly?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  8. #8

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    Oh, no crptcblade, your solution worked! I was posting that at the same time you were. Thank you guys so much for your help
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  9. #9

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    But, that still doesn't make sense why a field that had value was throwing that error, but if I append an empty string to it it works.??
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    I beleive that variables displays thier valus when you sequence to the next line (using F8), having said that the Value 'any' may be the
    previous secords value.



    Bruce.

  11. #11

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    No, that can't be it because I only get one record with my query.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  12. #12
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by crptcblade
    Try
    VB Code:
    1. mCertification = rs.Fields("Certification") & ""

    blindlizard, crptcblade,

    Sorry, my bad. I had been using the IIF (in reverse) which of course is different to blindlizard question. I had done:
    VB Code:
    1. .Fields("Equipment").Value = IIf(cboEquipment.Text = "", Null, cboEquipment.Text)




    Bruce.
    Last edited by Bruce Fox; Nov 24th, 2003 at 04:58 PM.

  13. #13
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    A solution w/o IIF....

    is to jsut append vbNullString ....
    VB Code:
    1. strMyString = rs.Fields("Something").Value & vbNullString
    and for numbers...
    VB Code:
    1. lngMyLong = CLng(Val(rs.Fields("Something").Value & vbNullString))


    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    But I still don't understand why it says I have a NULL when I do not. If I append an empty string I get my value fine.

    This gives me an error
    mCertification = rs.Fields("Certification")

    This gives me the value "any" from the DB
    mCertification = rs.Fields("Certification") & ""
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

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