Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

successful ms access insert? 2

Status
Not open for further replies.

Goalie3533

Programmer
Apr 14, 2004
53
US
I have an asp application that needs to check whether or not an ms access table "insert" statement was successful. If the new table row was successfully added, I need to inform the user of this. If it wasn't successful however, I need to halt all further execution of my code.

Does anyone know of a way to check whether or not a row was definately successfully inserted?

Thanks in advance.

-Goalie35
 
The best way is to run an SQL against the table to check for the record. Ideally, your table has a unique identifier that is part of the data inserted. Perform an SQL using the unique identifier as the "Where" statement and compare the return with what you inserted.

Without a unique identifier, you must devise some method of identifying the record - even if it is using your entire Insert data in the Where statement.

Looking up the "Last" record is not a good idea. For one thing, someone else may have inserted a new record between the time the first user inserted one and your page then attempted to verify the record - the first user's record would not be the last record.
 
A more efficient method (I would think) would be to use standard ASP error checking. Use "On Error Resume Next," clear your errors prior to inserting, and check for an error afterwards.

ADODB should be smart enough to throw an error if it doesn't receive a proper ok from the database.
 
ADODB [red]should[/red] be smart enough to throw an error if it doesn't receive a proper ok from the database.
Perhaps I'm a little paranoid, but if it is critical that the record be written, I would still perform an SQL select to verify the data.
 
I appreciate your paranoia. :)

But... what if the database is only placing the data in a temporary place and isn't really committing it, but is falsely returning it to you?

Just kidding. ;-)
 
That happened to me once, so I just retired and removed my monitary dependence from sneaky misbehaving databases.
 
MoLaker & Genimuse, thanks for both of your responses. I ultimately ended up going with performing a SQL select to verify the data but I appreciated both of your guys input.

-Goalie35
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top