Opdatere med et blankt datofelt
Hej Eksperter,Jeg skal have muligheden for at opdatere et datofelt, hvor indholdet bliver rettet til et tomt felt.
Jeg har fundet nedenstående kode her på eksperten, men jeg kan ikke få den til at virke.
Jeg får en "Type Mismatch" fejl på linjen:
rsUpdateEntry.Fields("datov") = " "& strfixdatov &" "
Datofeltet i access er sat til not required, og er en short date.
Tekst felter har intet problem med at være blanke.
Kode:
----------------
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsUpdateEntry 'Holds the recordset for the record to be updated
Dim strSQL 'Holds the SQL query for the database
Dim lngRecordNo 'Holds the record number to be updated
'Read in the record number to be updated
lngRecordNo = CLng(Request.Form("ID"))
'Create an ADO connection odject
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("db\test.mdb")
'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=test"
'Create an ADO recordset object
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM test WHERE ID=" & lngRecordNo
'Set the cursor type we are using so we can navigate through the recordset
rsUpdateEntry.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rsUpdateEntry.LockType = 3
'Open the tblComments table using the SQL query held in the strSQL varaiable
rsUpdateEntry.Open strSQL, adoCon
if Request.Form("datov") = "" then
strfixdatov = "NULL"
else
strfixdatov = Request.Form("datov")
end if
'Update the record in the recordset
rsUpdateEntry.Fields("bet") = Request.Form("bet")
rsUpdateEntry.Fields("datov") = " "& strfixdatov &" "
'Write the updated recordset to the database
rsUpdateEntry.Update
'Reset server objects
rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing
'Return to the update select page incase another record needs deleting
Response.Redirect "default.asp"
%>