I am trying to add a record from a list box to the database, but an error message
appears;
Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/new/addreporttodb.asp, line 22
Line 22 is
objRS.Fields("EventName") = Request.Form("txtEventName")
Can any help me on this?
Thanks in Advance
This is the code that i am using
Input Form
Code:
<%
Option Explicit
Dim StrConnect
%>
<!-- #INCLUDE FILE="ProjectConnection.asp" -->
<!-- #INCLUDE FILE="clock.inc" -->
<HTML>
<HEAD>
<TITLE>Add Event Report</TITLE>
</HEAD>
<BODY>
<body bgcolor="#99CCFF">
<font face="Arial">
<center><u><b><font size="7">Add an Event Report</font></center></b></u></p>
<BR>
<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "Events", strConnect, 3,3
If objRS.BOF and objRS.EOF Then
Response.Write "There are no events to write reports on"
Else
objRS.MoveFirst
Do While Not objRS.EOF
%>
Event Name
<FORM ACTION = "addreporttodb.asp" METHOD= "post">
<SELECT NAME="txtEventName" SIZE="1">
<%
Response.Write "<OPTION VALUE='" & objRS("EventName") & "'>"
Response.Write objRS("EventName") & "</OPTION>"
objRS.MoveNext
Loop
objRS.Close
Set objRS = Nothing
%>
</SELECT>
<P>Date<input type="text" name = "txtDate" size="20"><BR>
Report<BR>
<textarea name="txtReport" col="200" rows="12" wrap="virtual" cols="40"></textarea> <BR>
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit"><BR>
<% End If %>
</form>
</body>
</html>
Code to add data to DB
Code:
<!-- #include file="ProjectConnection.asp" -->
<!-- METADATA TYPE="typelib"
FILE="c:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
Dim strConnect
%>
<html>
<head>
<title>Add Report</title>
</head>
<body>
<%
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "EventReport", strConnect, adOpenKeySet, AdLockOptimistic
objRS.AddNew
objRS.Fields("EventName") = Request.Form("txtEventName")
objRS.Fields("Date") = Request.Form("txtDate")
objRS.Fields("Report") = Request.Form("txtReport")
objRS.Fields("Username") = Session("Username")
objRS.Update
objRS.Close
Set objRS = Nothing
Response.Redirect "eventreportconfirmation.asp"
%>
</body>
</html>