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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP and Access Databases

Status
Not open for further replies.

BurcBoyar

Programmer
Feb 18, 2002
24
0
0
TR
I have a strange problem with Access databases. When I try to add a new record, it adds it to to end of the database. That's OK. But after sometime it starts to add them to the beginning of the database. Can someone tell me how can I prevent it doing this? I need to add all the new records to the end of the database. Thanx for your answers.

It's code is like this :

dbPath = Server.MapPath("..\db\yyy.mdb")
set zzzz = server.createObject("ADODB.Connection")
set rs = server.createObject("ADODB.Recordset")
zzzz.Open ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbPath)
'veritabani.Open ("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & dbPath)

rs.activeconnection=zzzz
rs.locktype = adlockoptimistic
sqlstring = "SELECT * FROM bbbb"
rs.open sqlstring
rs.movelast
rs.addnew
rs("xxx")="xxx"
rs.update
rs.close

zzzz.close
 
incorperate the
DO WHILE RS.EOF before adding your record
this will ensure you are at the end of the record set I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
I'll try it but it happens after sometime. If it works I'll let you know. But I have another question for you: DO WHILE RS.EOF will move the cursor to the end of the database, I know it. But rs.movelast does it too. Is there a difference between them that I don't know???
 
movelast moves the record pointer to the last record
and
EOF returns true if the current record position is after the last record, otherwise false
so in this case if you wanted to add a record I would stay away from movelast due to the fact you are putting the cursor on the last record instead of putting it at the end of the records. Remember that the main objective to using the move methods are for navigating with the cursor mainly for viewing purposes. I know they are used often for other events but I personally like to keep them on the naigation side of things in order to find records and very seldomly inserting records in the middle etc. of a recordset.
I'm sure many will disagree with me but using the EOF will ensure you are always at the end of the rs. I help at your own risk, if I brake it sorry! But if I fixed it, let me know with a
star.gif
[thumbsup2]
admin@onpntwebdesigns.com
 
If you have the ability to change the structure of your database and it wouldn't cause too much code rewrite, you could add a counter column as the first field in the table.

When you inserted a row, this column will get incremented by 1 (You would not set it in your code, MS Access would do this for you).

When you do your SELECTs you can always ORDER BY this column and you would be sure to get records in the order they were entered into the database. If you ever needed to migrate to SQL Server, the counter column would then just become an identity column.

Thanks,

Gabe
 
Well, your way didn't work out too. I think there is something wrong with database not with code. But I'm not sure what it is. If anyone knows anything about it please respond.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top