Ah, I see.
So basically what you want to be able to do is see if the target record exists already (one select) and then either insert a new record if it doesn't (one insert) or update the existing one if ti does(one update). And obviously you do not want another user going in at the exact same time and creating the record while your in the middle of the process because you would have duplication and such.
You could use a recordset object andthe Open command to achieve this, remember I only stated that I prefered not to use that whenever possible, there is no rule against it
In the end it is up to you to decide which set you would want to use. You could use a static cursor and pessimistic lock, which would let you view the data more efficiently than the dynamic cursor and block others from changing the data, or an optimistic lock and dynamic cursor so that only the one record you are changing will be locked and only as the Update function is called to send any changes back.
My preference is to never use the recordset.Open command because it is inefficient. One way to get around using it in this case is to create the entry in the statitics db (if your tracking links total, not by date) at the same time you create the link in the first db. This way you will never have to see if the link has a corresponding entry in the statitics db, you can simply update and be on your way.
Tarwn's Solution #1
This assumes that you are tracking total hits to a link, not hits/day. It also assumes that users can add a new link to your list in the first database through some sort of minimal form.
Alter the processing page the submits the new link so that after it adds the link it then adds a new record to the statistics table with a hit count of 0.
When a user clicks a link and you need to update the number ofhits in the statistics db, simply do an update that increments the field: "Update MyTable Set HitsField = HitsField + 1". No muss, no fuss.
Dealing With Hits/Day
If you are doing hits by date then I guess there is no way around it, you will need to check if the record exists for the current date. No matter what type of record locking you do, since two users may try to add new records for the same link at the same time, you will not be able to lock a record tat doesn't exist anymore and one of them will receive an error for creating an identical record.
So here is my efficient, Open-free way of handling this.
1) Select from statistics for the link and date
2) If resulting recordet is EOF
2.1) On Error Resume Next
2.2) Attempt to insert new record
2.3) If an error has occurred, send the update string (record already existed)
2.5)Else (recordset is not EOF)
2.6) Increment hits field with an Update statement
Last Solution
The last solution is to, of course, use the Recordst.Open command to open the table. This is the least efficient because the database has to send you a copy of all the data in the table, if you used a dynamic lock the recordset will update portions of itself as you scroll through, wasting more time, etc. If you opened the whole table you will have to search through for a record that matches the link and date, which is much less efficient for ASP to do ten the originating db. Then at the end you will either be doing an update on one field (optimistic lock: the record will lock when you call update and possibly have an error if someone ele updated it; pessimistic: every record you looked at would lock when you looked at it, more communication, more lost processing time) or doing an insert (there is no way to lock a field that hasn't been aded to tghe db yet). In the end, even using these locking methods, you risk two users trying to insert a new record for the same criteria at the same time. I believe this will give you an error just like my earlier method.
---
Sorry tat I have provided no solid answers, but my approach is by preference rather than law. I am pretty sure that the information I have provided in the previous sections is all correct, but I cannot guarantee it 100% simply because some of it is based on benchmarks I have done in the past and some is based on information I have gleaned actually using the processes (but have never seen an adequate explanation from MS about). I hope tey have helped,
-T
01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website: