Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access_asp thread: Insert data into 2 separate tables


Message #1 by "Brooke Alexander" <noni_j@h...> on Thu, 23 Aug 2001 14:59:17
Can anyone help, I'm a newbie and I am trying to send data to 2 separate 

tables.  When I run my form in the web browser just by going to the tool 

bar, selecting file, etc....my response page just returns the heading:  

Try It Out...., and the data that I put in did not go to the database.  If 

you do the same thing except publish my form using FrontPage, my response 

page returns the following error message:

Error Type:

Microsoft VBScript runtime (0x800A01A8)

Object required: 'objConn'

/noniweb/curve2.asp, line 102.  



Below is the code for both my form, and response page.  If someone could 

help me I would really appreciate it.



Thank you in advance.



Brooke Alexander



Data Entry Form, curve.html:



<html>

<head>

<meta name = "Generator" Content= "Microsoft FrontPage 5.0">

<CENTER>

<H1>Future Curve</H1></CENTER>

<title>Future Curve</title>

</head>



<body>

<form action=curve2.asp method=post name=frmAdd>

 <input type=hidden name=action value=add>

 <table>

 <tr>

 <td>Employee ID Number</td>

 <td><input type= text name=txtEmployeeID size=10></td>

 <td width=10></td>

 <td> Future Curve Number</td>

 <td><input type= text name=txtFutureCurve size=10></td>

 </tr>

<tr>

 <td nowrap> First Name</td>

 <td><input type= text name=txtFirstName size=20></td>

 <td width=10></td>

 <td>Last Name</td>

 <td><input type= text name=txtLastName size=20></td>

 </tr>

 <td>Title or Position</td>

 <td><input type= text name=txtJobTitle size=20></td>

 <td width=10></td>

 <tr>

 <td>Code</td>

 <td><input type= text name=txtCode size=5></td>

 <td width=10></td>

 </tr>

<tr>

 <td>Supervisor</td>

 <td><input type= text name=txtSupervisior size=15></td>

 <td width=15></td>

 </tr>

<tr>

 <td>Question 5</td>

 <td colspan=4><textarea rows=3 cols=50 name=txtQuestion5></textarea></td>

 </tr>

<tr>

 <td>Question 6</td>

 <td colspan=4><textarea rows=3 cols=50 name=txtQuestion6></textarea></td>

 </tr>

<tr>

 <td>Question 7</td>

 <td colspan=4><textarea rows=3 cols=50 name=txtQuestion7></textarea></td>

 </tr>

<tr>

 <td>Question 8</td>

 <td colspan=4><textarea rows=3 cols=50 

name=txtQuestion8></textarea><p>       &

nbsp;       

 <applet code="fphover.class" codebase="./" width="268" height="27">

   <param name="color" value="#000080">

   <param name="hovercolor" value="#0000FF">

   <param name="textcolor" value="#FFFFFF">

   <param name="text" value="View Requirements Portfolio">

   <param name="effect" value="glow">

   <param name="url" valuetype="ref" value="Requirements.htm">

 </applet></td>

 </tr>

<tr>

 <td>Question 9</td>

 <td colspan=4><textarea rows=3 cols=50 name=S1></textarea><p>

 <TABLE cellSpacing=0 cellPadding=0 width=280 border=0>

<TBODY>

<TR>

<TD class=DashPartTitle width=280>

<NOBR>Individual Development Plan</NOBR>

</TD>  

<TD class=DashPartTitle style="CURSOR: hand" 

onclick="JavaScript:noni.style.display='block';" align=right>

<IMG src="USAFE FIRST LOOK Portal_files/plus.gif" border=0 width="11" 

height="11"></TD>

<TD class=DashPartTitle style="CURSOR: hand" 

onclick="JavaScript:noni.style.display='none';" align=right>

<IMG src="USAFE FIRST LOOK Portal_files/minus.gif" border=0 width="11" 

height="11"></TD>

</TR>

</TBODY>

</TABLE>

<SPAN id=noni style="DISPLAY: none">

<SPAN 

class=MSTheme-Label id=EmployeeID3_Label title=EmployeeID3 

style="PADDING-LEFT: 1px; LEFT: 274; OVERFLOW: visible; WIDTH: 96; 

POSITION: absolute; TOP: 607; HEIGHT: 38">

  Employee ID No.</SPAN><TEXTAREA id=EmployeeID3 title=EmployeeID3 

style="LEFT: 382; OVERFLOW: hidden; WIDTH: 1in; POSITION: absolute; TOP: 

615; HEIGHT: 0.187in" tabIndex=13 rows="1" cols="20"></TEXTAREA>Colin is a 

big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

 Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

Colin is a big dork<br>

</SPAN>

</TABLE> </td>

 </tr>

<tr>

 <td>Question 

10            &

nbsp;  </td> <td colspan=4><textarea rows=3 cols=50 

name=txtQuestion10></textarea></td>

 <p>

 </tr>

<tr>

 <td height=60><input type=button name=btnSubmit value=Submit></td>

 </tr>

 </table>

 </p>

 </form>





<script language = vbscript>

Sub btnSubmit_Onclick()

 'All fields are required

If Len (frmAdd.txtEmployeeID.value) = 0 then

 Alert "You must enter an Employee ID"

 frmAdd.EmployeeID.focus

 Exit Sub

ElseIf Len (frmAdd.txtFutureCurve.value) = 0 then

 Alert "You must enter a Future Curve Number"

 frmAdd.FutureCurve.focus

 Exit Sub

End If



'If we make it this far then submit the form

Call frmAdd.submit()

End Sub

</script>



</body>

</html>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



Response page, curve2.asp:

<HTML>

<HEAD>

<META NAME="GENERATOR" Content="Microsoft FrontPage 5.0">

<TITLE>Chapter 10 - SQL Statements That Modify Data</TITLE>

</HEAD>

<BODY>

Try It Out #2 - Process The Add Using The Insert Into Statement<br><br>



<%

'Declare variables needed

Dim strInsert

Dim strValues

Dim adCmdText



'Set required variables

adCmdText = 1

	

'***********************************************************

'* If an Add was requested, add the new club to the database

'***********************************************************

If Request.Form("Action") = "Add" Then

	

	'Start building the SQL strings with the required fields

	strInsert = "Insert into Employees (EmployeeID"

	strValues = "Values('" & CStr(Request.Form("txtEmployeeID")) & "'"

		

If Request.Form("Action") = "Add" Then

	

	'Start building the SQL strings with the required fields

	strInsert = "Insert into Future Curve (FutureCurve"

	strValues = "Values('" & CStr(Request.Form("txtFutureCurve")) & "'"

		





'Add First names

If Len (Request.Form("txtFirstName")) >0 Then

 'Add the column name to the insert string

 strInsert = strInsert & ",FirstName"

 strValues = strValues & "," & _

  Cstr(Request.Form("txtFirstName")) & "'"

End If



'Add Last names

If Len (Request.Form("txtLastName")) >0 Then

 'Add the column name to the insert string

 strInsert = strInsert & ",LastName"

 strValues = strValues & "," & _

  Cstr(Request.Form("txtLastName")) & "'"

End If



'Add Job Title

If Len (Request.Form("txtJobTitle")) >0 Then

 'Add the column name to the insert string

 strInsert = strInsert & ",JobTitle"

 strValues = strValues & "," & _

  Cstr(Request.Form("txtJobTitle")) & "'"

End If



'Add Code

If Len (Request.Form("txtcode")) >0 Then

 'Add the column name to the insert string

 strInsert = strInsert & ",Code"

 strValues = strValues & "," & _

  Cstr(Request.Form("txtCode")) & "'"

End If



'Add Supervisor

If Len (Request.Form("txtSupervisor")) >0 Then

 'Add the column name to the insert string

 strInsert = strInsert & ",Supervisor"

 strValues = strValues & "," & _

  Cstr(Request.Form("txtSupervisor")) & "'"

End If





'Create and open the database object

	Set objConn = Server.CreateObject("ADODB.Connection")

	objConn.Open "DSN=noni"



	'Create the command object

	Set objCmd = Server.CreateObject("ADODB.Command")



	'Set the command object properties

	Set objCmd.ActiveConnection = objConn

	objCmd.CommandText = strInsert & ") " & strValues & ")"

	objCmd.CommandType = adCmdText



	'Execute the command

	objCmd.Execute

		

	'Display the insert string

	Response.Write "The following insert string was executed and " & _

		"the values inserted into the Employees and Future Curve 

tables.<P>"

	Response.Write strInsert & ") " & strValues & ")"

	Response.Write strInsert & ") " & strValues & ")"



	

End If

End If

'Close and dereference database objects

Set objCmd = Nothing

objConn.Close

Set objConn = Nothing

%>



</body>

</html>








  Return to Index