PDA

View Full Version : retrieving record from database


pwgeary
06-11-2003, 09:11 AM
I have a ms access database that uses a linked table. The linked table links to a text file. The text file is updated using asp. The updated information comes from and outside source. So i have to connect to a sql 7 server. I run the script that will select just updated information and write it to the text file that is linked. If the is a new record it is fine, but the problem comes in when there is a change to an existing record. It will create 2 records. The original and a second that has 2 changed fields one could be any of the fields except the id and the second is the time field. So what i need to know is how to either select the most recent record or how to delete the first record. here is my select statement.
<%sql="Select * From Res Where Res.List_Price > 0 and (Res.Town like 'springfield' or Res.Town = 'Hyde Park') order by ID ASC" %>

Thanks for your help

Angelika
06-11-2003, 11:40 AM
<%
ADD NEW RECORD:
rs.Open"select max(ID) from Table_Name",conn
if RS.EOF=false and RS.BOF=false then
if isnull(RS(0))=false then
lvID = RS(0)+1
else
lvID=1
end if
end if
ID = lvID
RS.Close

RS.Open"select * from Table_Name",conn,3,3
RS.AddNew
RS.Fields("Fields_Name")=var_Name
RS.Fields("Fields_Name") =var_Name
RS.Fields("Fields_Name") =var_Name
RS.Fields("Fields_Name") =var_Name
RS.Fields("Fields_Name") = var_Name
RS.Fields("Fields_Name") = var_Name
RS.Update
RS.Close
Set RS = Nothing


UPDATE RECORD:
<%

strSQL = "select * from Table_Name "
strSQL = strSQL + "WHERE ID= "&var_ID&""

'For string var
'strSQL = strSQL + "WHERE ID= '"+var_ID+"'"

rs.Open strSQL ,conn,3,3
If Not lors.EOF Then
rs.MoveFirst
rs.Fields("Fields_Name") = var_Name
rs.Fields("Fields_Name") = var_Name
rs.Fields("Fields_Name") = var_Nameode
lors.Fields("Fields_Name") = var_Name
lors.Update
End If
rs.Close
Set rs = Nothing


DELETE RECORD:

strSQL = "SELECT * FROM Table_Name "
strSQL = strSQL + "WHERE ID= "&ID&" "
rs.Open strSQL,Conn,3,3

IF NOT rs.EOF THEN
rs.MoveFirst
rs.Delete
END IF
rs.Close
Set rs = Nothing

%>