+1 i et felt , men skal først læse den højeste
Hej..nedenstående kode bruger jeg til at gemme mine data i en tabel i databasen med. Men jeg vil gerne havde det sådan at den inden den skriver læser hvilket tal der er det højeste i feltet kommentar_nr og adderer 1 til og det nye tal skal den så skrive i feltet kommentar_nr i den nye record her... hvem kan hjælpe ?<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsAddComments 'Holds the recordset for the new record to be added
Dim SQL 'Holds the SQL query to query the database
'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../databaser/news.mdb")
'Create an ADO recordset object
Set rsAddComments = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
SQL = "SELECT * FROM kommentar;"
'Set the cursor type we are using so we can navigate through the recordset
rsAddComments.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rsAddComments.LockType = 3
'Open the recordset with the SQL query
rsAddComments.Open SQL, adoCon
'Tell the recordset we are adding a new record to it
rsAddComments.AddNew
'Add a new record to the recordset
rsAddComments.Fields("forfatter") = Request.Form("forfatter")
rsAddComments.Fields("overskrift") = Request.Form("overskrift")
rsAddComments.Fields("tekst") = Request.Form("tekst")
rsAddComments.Fields("nyhed_id") = Request.Form("id")
rsAddComments.Fields("kommentar_nr") = ?????
'Write the updated recordset to the database
rsAddComments.Update
'find id som vi lige har sat ind.
'sqlo = "SELECT max(ID_no) FROM beretningtabel"
'Set rso = adocon.Execute(sqlo)
'oid = Cint(rso(0))
'Reset server objects
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing
%>