Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183

    Unhappy Unanswered: Invalid use of null:Cstr

    This is the error I receive when trying to submit a new record, and higlights this code
    call rs.Open("SELECT @@IDENTITY As NewRecID", myCon)
    nRecID = CStr(rs("NewRecID"))
    call rs.Close

    which is obviously the code creating new RecordID as new records are added.
    I don't really have a control over creating this number it gets allocated,right?

    Could somebody give me an advice as what should I be looking for,this has worked in the past and not sure when exactly it stopped working.

    Thanks a lot everybody

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Code:
    call rs.Open("SELECT @@IDENTITY As NewRecID", myCon)
    nRecID = CStr(rs("NewRecID"))
    call rs.Close
    okie, that select statement if current returning null and you are trying to convert it to a string and thus your error.

    @@IDENTITY returns the last-inserted identity value. Is the record that you are inserting using an identity column?? If not that would likely return a null.

    I assume this follows straight after an insert statement yes?

    edit: just checked, null is returned if no identity column was used in the last insert
    Last edited by rokslide; 10-28-04 at 01:47.

  3. #3
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    Yes you are correct,that is what i have realised it is null, because INSERT code before that is not executing but I can't see why, debugging the code shows, all the values as expected,have gone through all the field names, it updates correctly but not saving a newly submitted record.

    pain in the a..

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    have you tried executing to code directly against the database??

  5. #5
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    can you explain a bit more,just like everything else my debuggin skills=VERY LIMITED

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    grab the sql the you are sending to the database to insert the record by doing a response.write on the line before you execute it.

    copy the sql and go to the database in the query analyzer and paste the sql in. then execute the statement in the analyzer.

    that way you might see what is happening.

  7. #7
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    Why didn't you say so, smart man, will do.
    Ta

    will let you know tomorrow how it went, have to nick out now
    Last edited by zobernjik; 10-28-04 at 02:09.

  8. #8
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    no worries, should at worse show the problem or rule out the sql as an issue

  9. #9
    Join Date
    Feb 2004
    Location
    Australia
    Posts
    183
    Thanks for your idea, the problem was that INSERT statement didn't like the order of some fields because the varchar submitted was trying to save as a field int so once i got that sorted it is cool.

    I am learning so much.

    Ta

  10. #10
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    excellent, glad I could help.

Posting Permissions

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