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

Insert or Update - that is the question

Status
Not open for further replies.

Einstein47

Programmer
Nov 29, 2001
737
US
My problem is that I don't know how to determine if I should do an insert or an update on an Access DB table.

I am writing the code for an online game. If the weekly winner exists in the winners table, then I want to update his/her score. However, if the winner has not won before there will be no record in the winner table for him/her, and I will need to insert a new record.

What is the best code to determine the update vs insert dilemma?

Also - can I use temp tables in Access and ASP? If I could then it may make my life easier, but I have no clue to the syntax of temp tables for Access. If anyone could point me to a good resource, I would be very happy. Einstein47
(How come we never see the headline, "Psychic Wins Lottery"?)
 
I think I have understood your meanings. The following is my thoughts:
First, open the table that stored the information of winners. Make a query to find if the specific winner you have retrieved from the scores of this week.

set obj_r = Server.CreateObject("ADODB.Recordset")
dim sql
sql = "select * from winner_table where name(or something else) ='"&name(or something else)&"'"
obj_r.Open sql,conn

now judge that whether the obj_r is empty. If it is, then INSERT a new record, else UPDATE the record.

I haven't test my idea. But I think it is available.
I hope it helps.

 
yeah it's a bummer that there arent any real sprocs in access.

Only 'temp tables' i've found in access are real tables created and dropped as required. codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top