Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Inserting with ASP


Message #1 by Tom Achtenberg <toma@f...> on Fri, 19 Jul 2002 13:14:21 -0700
I have the following data entry form on an ASP page.   I am on SQL Server 7.0 and IIS 5

------------beginning of form-----------------------------------------------------------------------------

<form name="verify" action="insertdata2.asp" method="post">
<table border=0>
<tr>
  <td width=20% rowspan=16>&nbsp;</td>
  <td>Artist ID</td>
  <td><input type="text" name="vartistid"size="10" maxlength="10"value=<%=request.form("artistid")%>></td>
</tr><tr>
 <td>Start Date</td>
 <td><input type="text" name="vstart_date" size="10"
maxlength="10"value=<%=request.form("start_date")%>></td>
</tr><tr>
 <td>Track</td>
 <td><input type="text" name="vtrack" size="1" maxlength="1"value=<%=request.form("track")%>></td>
</tr><tr>
 <td>Percent Down</td>
 <td><input type="text" name="vpercent_dn"value=<%=request.form("percent_dn")%>></td>
</tr><tr>
 <td>Total Goal</td>
 <td><input type="text" name="vtot_goal"value=<%=request.form("tot_goal")%>></td>
</tr><tr>
 <td>Total Contract</td>
 <td><input type="text" name="vtot_contract"value=<%=request.form("tot_contract")%>></td>
</tr><tr>
 <td>Stop Date</td>
 <td><input type="text" name="vstop_date" size="10" maxlength="10"value=<%=request.form("stop_date")%>></td>
</tr><tr>
 <td>Goal A</td>
 <td><input type="text" name="vgoal_a"value=<%=request.form("goal_a")%>></td>
</tr><tr>
 <td>Payment A</td>
 <td><input type="text" name="vpayment_a"value=<%=request.form("payment_a")%>></td>
</tr><tr>
 <td>Goal B</td>
 <td><input type="text" name="vgoal_b"value=<%=request.form("goal_b")%>></td>
</tr><tr>
 <td>Payment B</td>
 <td><input type="text" name="vpayment_b"value=<%=request.form("payment_b")%>></td>
</tr><tr>
 <td>Goal C</td>
 <td><input type="text" name="vgoal_c"value=<%=request.form("goal_c")%>></td>
</tr><tr>
 <td>Payment C</td>
 <td><input type="text" name="vpayment_c"value=<%=request.form("payment_c")%>></td>
</tr><tr>
 <td>Goal D</td>
 <td><input type="text" name="vgoal_d"value=<%=request.form("goal_d")%>></td>
</tr><tr>
 <td>Payment D</td>
 <td><input type="text" name="vpayment_d"value=<%=request.form("payment_d")%>></td>
</tr>
</table>
 <input type="submit"value="Submit">&nbsp;&nbsp;<input type="reset">
</form>
</body>
</html>
-----------------------end of form------------------------------------------------------------------------------
I have 2 different pages to actually insert the data.  One uses a command object and the other uses a recordset.  In both cases when
I press the submit button it just hangs up and does not insert the new record.  Below are the two insert pages.  Any ideas why they
hang up?

-----------------beginning of recordset page--------------------------------------------------------------
<%
	dim objRS, intNoOfRecords
	set objRS = server.createObject("adodb.recordset")

	objRS.open "fh_artist_contracts", strConnect, adOpenForwardOnly, adLockOptimistic, adCmdTable
	objRS.movelast
	intNoOfRecords = objRS("contractid")
	objRS.addnew

	objRS("artistid") = request.form("vartistid")
	objRS("start_date") = request.form("vstart_date")
	objRS("track") = request.form("vtrack")
	objRS("percent_dn") = request.form("vpercent_dn")
	objRS("tot_goal") = request.form("vtot_goal")
	objRS("tot_contract") = request.form("vtot_contract")
	objRS("stop_date") = request.form("vstop_date")
	objRS("goal_a") = request.form("vgoal_a")
	objRS("payment_a") = request.form("vpayment_a")
	objRS("goal_b") = request.form("vgoal_b")
	objRS("payment_b") = request.form("vpayment_b")
	objRS("goal_c") = request.form("vgoal_c")
	objRS("payment_c") = request.form("vpayment_c")
	objRS("goal_d") = request.form("vgoal_d")
	objRS("payment_d") = request.form("vpayment_d")

	objRS.update
	objRS.close

	objRS.open "Select count(*) as newrec from fh_artist_contracts " & _
		"where contractid > "& intNoOfRecords

	response.write objRS("newrec") & " record has been inserted<br><br>"

	objRS.close
	set objRS = nothing
%>

-------------end of recordset and beginning of command object--------------------------------------

<%
	dim objComm, intNoOfRecords
	set objComm = server.createObject("adodb.command")

	objComm.activeconnection = strConnect
	objComm.CommandText="insert into fh_artist_contracts (artistid, start_date, track, " & _
		"percent_dn, tot_goal, tot_contract, stop_date, goal_a, payment_a, " & _
		"goal_b, payment_b, goal_c, payment_c, goal_d, payment_d) values " & _
		"('"&<%request.form("artistid")%>&"','"&<%request.form("start_date")%>&"','"&<%request.form("tr
ack")%>&"',' " & _
		"<%request.form("percent_dn")%>&"','"&<%request.form("tot_goal")%>&"','"&<%request.form("tot_contra
ct")%>&"',' " & _
		"<%request.form("stop_date")%>&"','"&<%request.form("goal_a")%>&"','"&<%request.form("payment_a")%&
gt;&"',' " & _
		"<%request.form("goal_b")%>&"','"&<%request.form("payment_b")%>&"','"&<%request.form("goal_c")%>
&"',' " & _
		"<%request.form("payment_c")%>&"','"&<%request.form("goal_d")%>&"','"&<%request.form("payment_d")%&
gt;&"') "
	objComm.commandtype = adCmdText
	objComm.execute intNoOfRecords
	response.write intNoOfRecords & " record has been inserted<br><br>"

	set objComm = nothing
%>

------------end of code----------------------------------------------

Tom Achtenberg
Developer, Information Technologies
Food for the Hungry / US
(xxx) xxx-xxxx  (voice)
(xxx) xxx-xxxx  (fax)
TomA@f...

  Return to Index