If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Invalid use of null:Cstr

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-27-04, 20:50
zobernjik zobernjik is offline
Registered User
 
Join Date: Feb 2004
Location: Australia
Posts: 183
Unhappy 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
Reply With Quote
  #2 (permalink)  
Old 10-28-04, 00:38
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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 00:47.
Reply With Quote
  #3 (permalink)  
Old 10-28-04, 00:56
zobernjik zobernjik is offline
Registered User
 
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..
Reply With Quote
  #4 (permalink)  
Old 10-28-04, 01:00
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
have you tried executing to code directly against the database??
Reply With Quote
  #5 (permalink)  
Old 10-28-04, 01:00
zobernjik zobernjik is offline
Registered User
 
Join Date: Feb 2004
Location: Australia
Posts: 183
can you explain a bit more,just like everything else my debuggin skills=VERY LIMITED
Reply With Quote
  #6 (permalink)  
Old 10-28-04, 01:04
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
  #7 (permalink)  
Old 10-28-04, 01:07
zobernjik zobernjik is offline
Registered User
 
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 01:09.
Reply With Quote
  #8 (permalink)  
Old 10-28-04, 01:10
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
no worries, should at worse show the problem or rule out the sql as an issue
Reply With Quote
  #9 (permalink)  
Old 10-28-04, 21:54
zobernjik zobernjik is offline
Registered User
 
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
Reply With Quote
  #10 (permalink)  
Old 10-28-04, 21:56
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
excellent, glad I could help.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On