AspSmartupload - opdatering af database
Jeg har et problem med opdatering af en database, jeg kan godt oprette en ny post i databasen med et tekstfelt, samt upload af en fil, hvis navn der samtidig også bliver lagt i basen. Resultatet kan jeg godt trække ud af basen.Men jeg har problemer men at opdatere posterne i databasen:
Jeg får flg. fejl.:
Error Type:
aspSmartUpload (0x800A0009)
Subscript out of range
/horn/update_entry.asp, line 16
Linje 16: mySmartUpload.Upload
Iflg. aspSmartUploads FAQ er fejlen:
PRB: aspSmartUpload error '800a0009' Subscript out of range
This error occurs when the asp is directly executed instead of being called from an HTML form with an ENCTYPE="multipart/form-data" tag.
Men hvis jeg indsætter ENCTYPE="multipart/form-data" i formularen får jeg følgende fejl:
Cannot use Request.Form collection after calling BinaryRead.
Min kode:
update_form.asp:
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rs '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.QueryString("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 rs = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM test WHERE ID=" & lngRecordNo
'Open the recordset with the SQL query
rs.Open strSQL, adoCon
%>
<html>
<head>
<title>Update Form</title>
</head>
<body bgcolor="white" text="black">
<!-- Begin form code -->
<form name="form" method="post" ENCTYPE="multipart/form-data" action="update_entry.asp">
Text: <input type="text" name="text" maxlength="20" value="<% = rs("text") %>">
<br>
File: <input type="file" name="file" maxlength="50" value="<% = rs("file") %>">
<input type="hidden" name="ID" value="<% = rs("ID") %>">
<input type="submit" name="Submit" value="Submit">
</form>
<!-- End form code -->
</body>
</html>
<%
'Reset server objects
rs.Close
Set rs = Nothing
Set adoCon = Nothing
%>
update_entry.asp:
<%
' Variables
' *********
Dim mySmartUpload
Dim file
Dim intCount
intCount=0
' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Upload
' ******
mySmartUpload.Upload
' Select each file
' ****************
For each file In mySmartUpload.Files
' Only if the file exist
' **********************
If not file.IsMissing Then
' Save the files with his original names in a virtual path of the web server
' ****************************************************************************
file.SaveAs("/horn/images/"& file.FileName)
' sample with a physical path
'file.SaveAs("c:\" & file.FileName)
'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 test.* 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
'Update the record in the recordset
rsUpdateEntry.Fields("text")= mysmartupload.Form("text")
rsUpdateEntry.Fields("file")= file.FileName
'Write the updated recordset to the database
rsUpdateEntry.Update
End If
' Display the number of files which could be uploaded
' ***************************************************
Response.Write("<BR>" & mySmartUpload.Files.Count & " file(r) kunne blive uploaded.<BR>")
' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(r) uploaded.<BR>")
Next
'Reset server objects
rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing
'Return to the update select page incase another record needs deleting
Response.Redirect "update_select.asp"
%>
Er nogle eksperter deruden med en løsning på dette problem?
