August 4th, 2007, 02:56 AM
Loop to insert record
I have to insert multiple record, the code is like this:
while rs.eof = false
commUpdate.CommandText = "insert into table a select.....where b.col1 = " & rs.Fields("col1").Value
then I need to display the newly inserted record immediately.
I would like to know if there would be any problem to insert record inside a loop and then display the record immediately. I mean would this increase the loading time of the page?
Or is it possible that the page load before inserting the records (that means I can't see the newly inserted record)?
August 4th, 2007, 06:09 AM
add a response.write
add a response.write records and then through what displayed you can know which one(s) have any problem.
Originally Posted by deadfish
August 4th, 2007, 07:31 AM
I'm not sure I understand fully what you're trying to accomplish. Yes, you can loop through and insert data as needed. Once you're done inserting the records, just run a SELECT statement to display the results.
August 4th, 2007, 05:30 PM
You should review your insert sql, you can't use WHERE in an insert statement.
And for myself, I go out of my way to avoid doing db operations from within a loop.
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain
August 4th, 2007, 05:38 PM
August 5th, 2007, 07:56 PM
Thanks for your reply.
Actually I just afraid that the select statement runs before completing the insert statement. That means when I select
records from the table, I cannot view all the newly inserted records....
I may try to avoid the loop.....
August 5th, 2007, 09:38 PM
What does your reply have to do with the question? You can also use WHERE with an UPDATE and that wasn't asked about either.
Originally Posted by jmurrayhead
August 5th, 2007, 09:42 PM
If possible that's my recommendation.
You can issue another sql statement right after your insert to retrieve the newly created ID if your id column is an identity or autonumber column, code like
.. insert code blah blah
set rsid = con.execute("select @@identity as MyID")
response.write rsid("MyID") 'this should be the new ID