Solved

Multiple Insert of rows from repeat region

Posted on 2007-11-27
34
519 Views
Last Modified: 2011-09-20
Hi Experts.

I am using Dreamweaver 8 and SQL 2005.  I have a page that displays any number of rows that meet a certain criteria in a repeat region.  I would like to insert all rows that are displayed into a table on a single submit.  Can anyone advise if this is possible and point me in the right direction if so.  

My code (see below) at the moment inserts the first record of the repeat region into the table I wish to insert all the repeat region rows into.

Many thanks for any help with this

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="../../Connections/camsmith.asp" -->
<!--#include file="../../ScriptLibrary/incSmartMailer.asp" -->
<% Session.LCID = 2057 %>

<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
  If condition = "" Then
    MM_IIf = ifFalse
  Else
    MM_IIf = ifTrue
  End If
End Function
%>
<%
If (CStr(Request("MM_insert")) = "form1") Then
  If (Not MM_abortEdit) Then
    ' execute the insert
    Dim MM_editCmd

    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_camsmith_STRING
    MM_editCmd.CommandText = "INSERT INTO dbo.matching_emails_sent (meClientName, meMinPrice, meMaxPrice, meTown, meBuildingType, meMinBeds, mMinPublicRooms) VALUES (?, ?, ?, ?, ?, ?, ?)"
    MM_editCmd.Prepared = true
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, 30, Request.Form("meClientName")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 5, 1, -1, MM_IIF(Request.Form("meMinPrice"), Request.Form("meMinPrice"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 5, 1, -1, MM_IIF(Request.Form("meMaxPrice"), Request.Form("meMaxPrice"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 201, 1, 60, Request.Form("meTown")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 201, 1, 15, Request.Form("meBuildingType")) ' adLongVarChar
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 5, 1, -1, MM_IIF(Request.Form("meMinBeds"), Request.Form("meMinBeds"), null)) ' adDouble
    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 5, 1, -1, MM_IIF(Request.Form("meMinPublicRooms"), Request.Form("meMinPublicRooms"), null)) ' adDouble
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
  End If
End If
%>
<%
Dim matching__MMColParam
matching__MMColParam = "1"
If (Request.QueryString("mClientName") <> "") Then
  matching__MMColParam = Request.QueryString("mClientName")
End If
%>
<%
Dim matching
Dim matching_numRows

Set matching = Server.CreateObject("ADODB.Recordset")
matching.ActiveConnection = MM_camsmith_STRING
matching.Source = "SELECT * FROM dbo.PropertyMatching WHERE mClientName = '" + Replace(matching__MMColParam, "'", "''") + "'"
matching.CursorType = 0
matching.CursorLocation = 2
matching.LockType = 1
matching.Open()

matching_numRows = 0
%>
<%
Dim matchedproperty__MMColParam
matchedproperty__MMColParam = "1"
If (Request.QueryString("mMinPrice") <> "") Then
  matchedproperty__MMColParam = Request.QueryString("mMinPrice")
End If
%>
<%
Dim matchedproperty__MMColParam2
matchedproperty__MMColParam2 = "9999999999"
If (Request.QueryString("mMaxPrice")  <> "") Then
  matchedproperty__MMColParam2 = Request.QueryString("mMaxPrice")
End If
%>
<%
Dim matchedproperty__MMColParam3
matchedproperty__MMColParam3 = "0"
If (Request.QueryString("mMinBeds")   <> "") Then
  matchedproperty__MMColParam3 = Request.QueryString("mMinBeds")  
End If
%>
<%
Dim matchedproperty__MMColParam4
matchedproperty__MMColParam4 = "0"
If (Request.QueryString("mMinPublicRooms")    <> "") Then
  matchedproperty__MMColParam4 = Request.QueryString("mMinPublicRooms")  
End If
%>
<%
Dim matchedproperty__varTown
matchedproperty__varTown = "%"
If (Request.QueryString("mTown")     <> "") Then
  matchedproperty__varTown = Request.QueryString("mTown")    
End If
%>
<%
Dim matchedproperty__varBType
matchedproperty__varBType = "%"
If (Request.QueryString("mBuildingType")      <> "") Then
  matchedproperty__varBType = Request.QueryString("mBuildingType")    
End If
%>
<%
Dim matchedproperty
Dim matchedproperty_numRows

Set matchedproperty = Server.CreateObject("ADODB.Recordset")
matchedproperty.ActiveConnection = MM_camsmith_STRING
matchedproperty.Source = "SELECT *  FROM dbo.Property  WHERE pPrice > " + Replace(matchedproperty__MMColParam, "'", "''") + " and pPrice < " + Replace(matchedproperty__MMColParam2, "'", "''") + " and pBedRooms >= " + Replace(matchedproperty__MMColParam3, "'", "''") + " and pPublicRooms >= " + Replace(matchedproperty__MMColParam4, "'", "''") + " and pTown like '" + Replace(matchedproperty__varTown, "'", "''") + "' and pBuildingType like '" + Replace(matchedproperty__varBType, "'", "''") + "' and pStage = 'For Sale'"
matchedproperty.CursorType = 0
matchedproperty.CursorLocation = 2
matchedproperty.LockType = 1
matchedproperty.Open()

matchedproperty_numRows = 0
%>

<%
Dim template
Dim template_numRows

Set template = Server.CreateObject("ADODB.Recordset")
template.ActiveConnection = MM_camsmith_STRING
template.Source = "SELECT * FROM dbo.htmlemail ORDER BY htmlemailref DESC"
template.CursorType = 0
template.CursorLocation = 2    
template.LockType = 1
template.Open()

template_numRows = 0  
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
matchedproperty_numRows = matchedproperty_numRows + Repeat1__numRows
%>
<%
response.AddHeader "Content-Type", "text/html;Charset=iso-8859-1"
%>

<%
' Smart Mailer 1.0.7
' Send on submit of form form1
' Use progress blue_mailprogress.htm
'   dimentions 300, 100
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
  Server.ScriptTimeout = 9999
  Set sm1 = new SmartMailer
  sm1.checkVersion "1.07"
  sm1.contentCharset = "us-ascii"
  Session.CodePage = sm1.getCodepage()
  sm1.smtpSetup "post.bmcsolutions.co.uk", "25", "property@easiproperty.net", "8order1304"
  sm1.pickup = ""
  sm1.component = "cdo"
  sm1.tmpFolder = ""
  sm1.embedImages = false
  sm1.progressBar = "blue_mailprogress.htm"
  sm1.ignore_errors = false
  sm1.useQueue = false
  sm1.setFrom "Easi Property Matches", "property@easiproperty.co.uk"
  sm1.setTo "Grant Ballantyne", "gb@broomlands.com"
  sm1.setCc "Client Name Here", "property@easiproperty.net"
  sm1.setBcc "Julie Hossack", "jp@abcactive.com"
  sm1.Subject = "Your Easi Property Matches"
  ' using template for body
  sm1.setBody_Template_html "templateemailmatch_send.asp"
  ' Attachments none
  sm1.sendMail "one"
  Response.Redirect "../solicitor_estateagency_viewmatchingclients.asp"
end if
SM_mailAction = getMailAction()
%>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="JavaScript">
<!--

function showMailProgressWindow(progressFile,popWidth,popHeight) { //v1.00
  if (document.MM_returnValue!=false) {
    var w = 480, h = 340;
    if (document.all || document.layers || document.getElementById) {
      w = screen.availWidth; h = screen.availHeight;}
    var leftPos = (w-popWidth)/2, topPos = (h-popHeight)/2;
    document.progressWindow = window.open(progressFile,'ProgressWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + popWidth + ',height='+popHeight);
    document.progressWindow.moveTo(leftPos, topPos);document.progressWindow.focus();
   window.onunload = function () {document.progressWindow.close();};
} }
//-->
</script>
<title>Easi Property HTML Email Template 1</title>
<style>
body {
      margin-top:0px;
      margin-left:0px;
      margin-right:0px;
      margin-bottom:0px;
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 11px;
}

a {
color: #003399;
text-decoration: none;
}

a:hover {
color: #000099;
text-decoration: underline;
}
h1 {
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 12px;
      font-weight: bold;
      color: #0C2053;
      margin-top: 5px;
      margin-right: 5px;
      margin-bottom: 5px;
      margin-left: 5px;
}
.style1 {color: #FFFFFF}
h2 {
      font-weight: bold;
      color: #990000;
      font-size: 11px;
      line-height: normal;
      margin: 0px;
      padding: 0px;
}
</style>
</head>
<% Session("mMinPrice") = Request.QueryString("mMinPrice") %>
<% Session("mMaxPrice") = Request.QueryString("mMaxPrice") %>
<% Session("mMinBeds") = Request.QueryString("mMinBeds") %>
<% Session("mMinPublicRooms") = Request.QueryString("mMinPublicRooms") %>
<% Session("mTown") = Request.QueryString("mTown") %>
<% Session("mBuildingType") = Request.QueryString("mBuildingType") %>
<% Session("mClientName") = (matching.Fields.Item("mClientName").Value) %>
<BODY ><img src='http://www.c-f-1.com/o.aspx?e=NTU3MDQzMDk2&c=1' height='1' width='1'/><center>
</center>
<form action="<%=SM_mailAction%>" method="POST" name="form1" onSubmit="showMailProgressWindow('blue_mailprogress.htm?<%=Session.SessionId%>',300,100)">
  <br>
  <table width="500" border="0" align="center" cellpadding="0" cellspacing="3" style="border: 1px solid #666666; ">
    <tr>
      <td height="25" colspan="3" bgcolor="#0C2053"><span class="style1"> &nbsp;[Viewing:
          Template 1] </span></td>
    </tr>
    <tr>
      <td colspan="3" valign="top" background="http://www.easiproperty.net/graphics/cms_bg_header.jpg" bgcolor="#024B8F"><img src="http://www.easiproperty.net/graphics/menu2/sea_logo_l.jpg" alt="Solicitor Estate Agency Property Management" width="400" height="65" hspace="0" vspace="0" /></td>
    </tr>
    <tr>
      <td colspan="3" valign="middle" bgcolor="#CBD6E0"><h1>Dear <%=(matching.Fields.Item("mClientName").Value)%></h1></td>
    </tr>
    <tr>
      <td colspan="3" align="left" valign="top"><table width="99%" border="0" cellpadding="5" cellspacing="0" style="width:100%;" >
          <tr>
            <td width="76%" valign="top"><h2>Easi-Property Matches</h2>
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="45%">&nbsp;</td>
                  <td width="15%">&nbsp;</td>
                </tr>
                <tr>
                  <td width="45%"><p><strong>Matched Properties </strong></p></td>
                  <td width="15%"><p><strong>Price</strong></p></td>
                </tr> <%
While ((Repeat1__numRows <> 0) AND (NOT matchedproperty.EOF))
%>
                <tr>
                 
                    <td width="45%"><p><a href="http://www.easiproperty.net/campbellsmith_propertydetails.asp?pRef=<%=(matchedproperty.Fields.Item("pRef").Value)%>"><%=(matchedproperty.Fields.Item("pAddress1").Value)%>, <%=(matchedproperty.Fields.Item("pAddress2").Value)%>, <%=(matchedproperty.Fields.Item("pTown").Value)%></a></p></td>
                    <td width="15%"><p><%= FormatCurrency((matchedproperty.Fields.Item("pPrice").Value), 0, -2, -2, -2) %></p></td>
</tr> <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  matchedproperty.MoveNext()
Wend
%>
</div>
              </table>
              <p>&nbsp; </p>
              <p><a href="http://www.c-f-1.com/d.aspx?e=NTU3MDQzMDk2&c=1&linkID=420296" target="_blank" style="font-stretch:extra-condensed; font-weight: bold;"></a><br>
                    <br>
                    <br>
              <strong><em>Regards</em> </strong></p>
              <h2>EASI Property <br>
                Estate-Agent Solicitor Internet <br>
                Property Management </h2>
              <br>
                <a href="http://www.easiproperty.net" target="_blank">www.easiproperty.net</a><br>
                </p>            </td>
            <td width="24%" height="350" valign="top" bgcolor="#E7ECF1"><img src="http://www.easiproperty.net/graphics/easiproperty_sidebar.jpg" alt="EASI Property Management" width="110" height="350"></td>
          </tr>
      </table></td>
    </tr>
    <tr>
      <td colspan="3" align="left" valign="top" bgcolor="#CBD6E0"><p><br>
        We respect your privacy. We do not share the names and e-mail addresses
            of our clients, vendors or subscribers with any third party. See
            our <a href="http://www.easiproperty.net/privacy.asp">privacy statement</a> for
            details about our policy.</p>
          <p>If you wish to unsubscribe or do not wish to receive any further
            email, <a href="http://www.easiproperty.net">please unsubscribe by
            clicking here</a> and enter your details.<br>
        </p></td>
    </tr>
    <tr>
      <td colspan="2" align="left" bgcolor="#CBD6E0">&nbsp;</td>
      <td align="left" valign="top" bgcolor="#CBD6E0">&nbsp;</td>
    </tr>
    <tr>
      <td width="165" align="left" bgcolor="#CBD6E0">&nbsp;</td>
      <td width="213" align="left" bgcolor="#CBD6E0"><input name="meClientName" type="hidden" id="meClientName" value="<%=(matching.Fields.Item("mClientName").Value)%>">
      <input name="meMinPrice" type="hidden" id="meMinPrice" value="<%=(matching.Fields.Item("mMinPrice").Value)%>">
      <input name="meMaxPrice" type="hidden" id="meMaxPrice" value="<%=(matching.Fields.Item("mMaxPrice").Value)%>">
      <input name="meTown" type="hidden" id="meTown" value="<%=(matching.Fields.Item("mTown").Value)%>">
      <input name="meBuildingType" type="hidden" id="meBuildingType" value="<%=(matching.Fields.Item("mBuildingType").Value)%>">
      <input name="meMinBeds" type="hidden" id="meMinBeds" value="<%=(matching.Fields.Item("mMinBeds").Value)%>">
      <input name="meMinPublicRooms" type="hidden" id="meMinPublicRooms" value="<%=(matching.Fields.Item("mMinPublicRooms").Value)%>"></td>
      <td width="108" align="left" valign="top" bgcolor="#CBD6E0"><input type="submit" name="Submit2" value="Send Email"></td>
    </tr>
    <tr>
      <td height="20" colspan="3" align="left" valign="top" bgcolor="#0C2053">&nbsp;</td>
    </tr>
  </table>
  <br>
  <input type="hidden" name="MM_insert" value="form1">
</form>
</BODY>
</html>
<%
matching.Close()
Set matching = Nothing
%>
<%
matchedproperty.Close()
Set matchedproperty = Nothing
%>

<%
template.Close()
Set template = Nothing
%>


0
Comment
Question by:grantballantyne
  • 16
  • 16
  • 2
34 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 20362409
Hi grant,

One, please use the code snippet box from now on to paste in this much code...it makes questions like this much easier to read.

>> Can anyone advise if this is possible and point me in the right direction if so.

Yes, it is possible to do this but not from Dreamweaver's native behaviors.  You would either need to learn how to code this manually or go out and purchase a third-party extension that supports this.
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20364219
Jason is correct, DW will not do this natively.  We can code it manually, and it's not that difficult, but from that point on you might only be able to edit your page in Code view.  The reason is that DW will get 'upset' because it is no longer in control of the code to render the page.

This page won't run on my machine, because I don't not have the files that accompany it.  Therefore you'll have to explain what's happening on the page currently, and where your new logic needs to fit.  If you can use line numbers in your description I'll paste the code into my editor and take a look.
0
 

Author Comment

by:grantballantyne
ID: 20365897
Thanks for the advise guys,

Can you recommend a third party extension to achieve this?

Thanks
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20365985
I don't use 3rd party extensions because if something breaks, hardly anyone can help you out!   Once you've learned the ASP to make it happen then you can use it in your future projects!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 20367224
There are two third party extensions I'm aware of (I'm sure there are more) and both have decent support options.  They are expensive though ($200+)

The first is the Adobe Developer Toolkit, which used to be the Interakt suite of extensions and that has a number of advanced insert and update behaviors (insert/update multiple records, insert update to multiple tables, etc) and is wizard-based.

The other is the Web Assist stuff, specifically Data Assist.  
0
 

Author Comment

by:grantballantyne
ID: 20373856
Rouchie

I have created two simple tables (tablea & tableb).  Both tables have three fields (ref, field1, field3).  At the moment I have two rows of data in tablea which is displayed as a repeat region (see link below)
http://www.easiproperty.net/CMS/testdisplay.asp

What I would like to do is to insert both rows of data displayed in the repeat region into tableb when submitting the form.

I also attach the simple code for the page above.

Thanks for any help



<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->
 
 

<%

Dim tablea

Dim tablea_numRows
 

Set tablea = Server.CreateObject("ADODB.Recordset")

tablea.ActiveConnection = MM_camsmith_STRING

tablea.Source = "SELECT *  FROM dbo.tablea"

tablea.CursorType = 0

tablea.CursorLocation = 2

tablea.LockType = 1

tablea.Open()
 

tablea_numRows = 0

%>
 

<%

Dim Repeat1__numRows

Dim Repeat1__index
 

Repeat1__numRows = -1

Repeat1__index = 0

tablea_numRows = tablea_numRows + Repeat1__numRows

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />

<script src="../includes/common/js/base.js" type="text/javascript"></script>

<script src="../includes/common/js/utility.js" type="text/javascript"></script>

<script src="../includes/skins/style.js" type="text/javascript"></script>
 

</head>
 

<body>

<form id="form1" name="form1">

  <table width="400" border="0">

    <tr>

      <td>Ref      </td>

      <td>Field 1 </td>

      <td>Field 2 </td>

    </tr>

    <% 

While ((Repeat1__numRows <> 0) AND (NOT tablea.EOF)) 

%> <tr>

     

  <td><%=(tablea.Fields.Item("field1").Value)%></td>

  <td><%=(tablea.Fields.Item("field2").Value)%></td>

  <td><%=(tablea.Fields.Item("field3").Value)%></td>

 

</tr> <% 

  Repeat1__index=Repeat1__index+1

  Repeat1__numRows=Repeat1__numRows-1

  tablea.MoveNext()

Wend

%>

    <tr>

      <td>&nbsp;</td>

      <td>&nbsp;</td>

	

	  

	  

      <td><div align="right">

        <input type="submit" name="Submit" value="Submit" />

      </div></td>

    </tr>

  </table>
 

  

</form>
 
 

<p>&nbsp;</p>

</body>

</html>

<%

tablea.Close()

Set tablea = Nothing

%>

Open in new window

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20374172
Good work.  This type of page is nice and easy to work with.
Look at what I've added here.  There's a counter variable that starts at 1, then increases as we loop through the database.  The counter value is used to name the form fields (you'll have to look in the final rendered HTML to see this work), so you'll get form fields called,  Ref_1, Ref_2, Ref_3 ...
Finally we save the value of counter in a hidden field.  On the next page (where we insert the values) we can read the value of counter back and then start our loop.

See if this page works without errors, then send me the basic code for the insert page and I'll do the modifications for you.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<%

Dim tablea

Dim tablea_numRows

Set tablea = Server.CreateObject("ADODB.Recordset")

tablea.ActiveConnection = MM_camsmith_STRING

tablea.Source = "SELECT *  FROM dbo.tablea"

tablea.CursorType = 0

tablea.CursorLocation = 2

tablea.LockType = 1

tablea.Open()

tablea_numRows = 0
 

Dim Repeat1__numRows

Dim Repeat1__index

 

Repeat1__numRows = -1

Repeat1__index = 0

tablea_numRows = tablea_numRows + Repeat1__numRows

%>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />

<script src="../includes/common/js/base.js" type="text/javascript"></script>

<script src="../includes/common/js/utility.js" type="text/javascript"></script>

<script src="../includes/skins/style.js" type="text/javascript"></script>

</head>

 

<body>

<form id="form1" name="form1">

  <table width="400" border="0">

    <tr>

      <td>Ref      </td>

      <td>Field 1 </td>

      <td>Field 2 </td>

    </tr>

    <% 

Dim counter

counter = 1

While ((Repeat1__numRows <> 0) AND (NOT tablea.EOF)) 

%>

<tr>

  <td><input type="text" name="Ref_<%=counter%>" value="<%=(tablea.Fields.Item("field1").Value)%>" /></td>

  <td><input type="text" name="Field1_<%=counter%>" value="<%=(tablea.Fields.Item("field2").Value)%>" /></td>

  <td><input type="text" name="Field2_<%=counter%>" value="<%=(tablea.Fields.Item("field3").Value)%>" /></td>

</tr> 

<% 

  Repeat1__index=Repeat1__index+1

  Repeat1__numRows=Repeat1__numRows-1

  counter = counter + 1

  tablea.MoveNext()

Wend

%>

    <tr>

      <td>&nbsp;</td>

      <td>&nbsp;</td>

      <td><div align="right">

        <input type="hidden" name="counterTotal" value="<%=counter%>" />

        <input type="submit" name="Submit" value="Submit" />

      </div></td>

    </tr>

 </table>

</form>

</body>

</html>

<%

tablea.Close()

Set tablea = Nothing

%>

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20374372
Thanks very much for this Rouchie,

I have used your code and the page displays without errors - see link below
http://www.easiproperty.net/CMS/testdisplay.asp

I do not actually have an insert page as yet.  What I hoped to do was to keep it as simple as possible and try to understand what you have done and how it works - then I will try and pull this into the actual site pages.  

Please find attached the code for a blank insert page (called testinsert.asp) - are you able to fit your code into this page to insert the two rows of data collected from the page you have already provided.

Thanks very much for your help with this


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>
 

<body>

</body>

</html>

Open in new window

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20374891
>> are you able to fit your code into this page to insert the two rows of data collected from the page you have already provided.

Yes but things will get much more complicated as you will have multiple logic paths to try and keep up with.
It would be MUCH simpler as a seperate page, but either way is fine by me.

I wanted a basic insert page so I can see how DW creates the basic database connection object.  Do me a favour and create a false page with the following form fields, Ref_1, Field_1, Field_2

Get DW to add the database code to perform a basic insert to the table using the above 3 fields.  I'll then modify that logic to provide the final step to this issue.
0
 

Author Comment

by:grantballantyne
ID: 20375041
Hi Rouchie

I am happy to submit the rows of data on the subsequent page.

Please see attached the code for the insert page with the form values you mentioned.

Thanks again
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<%

Dim MM_editAction

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))

If (Request.QueryString <> "") Then

  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)

End If
 

' boolean to abort record edit

Dim MM_abortEdit

MM_abortEdit = false

%>

<%

' IIf implementation

Function MM_IIf(condition, ifTrue, ifFalse)

  If condition = "" Then

    MM_IIf = ifFalse

  Else

    MM_IIf = ifTrue

  End If

End Function

%>

<%

If (CStr(Request("MM_insert")) = "form1") Then

  If (Not MM_abortEdit) Then

    ' execute the insert

    Dim MM_editCmd
 

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

    MM_editCmd.ActiveConnection = MM_camsmith_STRING

    MM_editCmd.CommandText = "INSERT INTO dbo.tableb ([ref], field1, field2) VALUES (?, ?, ?)" 

    MM_editCmd.Prepared = true

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("Ref_1"), Request.Form("Ref_1"), null)) ' adDouble

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, 10, Request.Form("Field_1")) ' adLongVarChar

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, 10, Request.Form("Field_2")) ' adLongVarChar

    MM_editCmd.Execute

    MM_editCmd.ActiveConnection.Close

  End If

End If

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>
 

<body>

<form id="form1" name="form1" method="POST" action="<%=MM_editAction%>">

  <table width="400" border="0">

    <tr>

      <td width="127">Ref</td>

      <td width="153"><label>

        <input type="text" name="Ref_1" id="Ref_1" />

      </label></td>

      <td width="106">&nbsp;</td>

    </tr>

    <tr>

      <td>Field 1</td>

      <td><input type="text" name="Field_1" id="Field_1" /></td>

      <td>&nbsp;</td>

    </tr>

    <tr>

      <td>Field 2</td>

      <td><input type="text" name="Field_2" id="Field_2" /></td>

      <td>&nbsp;</td>

    </tr>

    <tr>

      <td>&nbsp;</td>

      <td colspan="2"><label>

        <div align="right">

          <input type="submit" name="button" id="button" value="Submit" />

        </div>

      </label></td>

    </tr>

  </table>
 

  <input type="hidden" name="MM_insert" value="form1" />

</form>

</body>

</html>

Open in new window

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20380593
Okay first we read the value of the counter back from the previous page, then use that number to loop through all the submitted form fields.  We execute an insert for each time the loop passes through:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<%

Dim MM_editAction

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))

If (Request.QueryString <> "") Then

  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)

End If
 

' IIf implementation

Function MM_IIf(condition, ifTrue, ifFalse)

  If condition = "" Then

    MM_IIf = ifFalse

  Else

    MM_IIf = ifTrue

  End If

End Function
 
 

' read back counter value and convert to integer (number) value

Dim counter

counter = CInt(Request.Form("counterTotal"))
 

' loop through all values in counter and insert for each one

For i = 1 to counter

    Dim MM_editCmd

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

    MM_editCmd.ActiveConnection = MM_camsmith_STRING

    MM_editCmd.CommandText = "INSERT INTO dbo.tableb ([ref], field1, field2) VALUES (?, ?, ?)" 

    MM_editCmd.Prepared = true

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, MM_IIF(Request.Form("Ref_" & counter), Request.Form("Ref_" & counter), null)) ' adDouble

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, 10, Request.Form("Field1_" & counter)) ' adLongVarChar

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, 10, Request.Form("Field2_" & counter)) ' adLongVarChar

    MM_editCmd.Execute

    MM_editCmd.ActiveConnection.Close

Next

Set MM_editCmd = Nothing

%>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<p>The data was successfully saved into the database!</p>

<p>Time for a beer... :-)</p>

</body>

</html>

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20381252
Hi Rouchie

Thanks for the insert page code.  I have added this to the insert page which returns an error as per below:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]The parameterized query '(@P1 float,@P2 text,@P3 text)INSERT INTO dbo.tableb ([ref], fiel' expects the parameter '@P2', which was not supplied.

/CMS/testinsert.asp, line 34

Apologies this is probably my fault as I did not mention to you that the column ref is an identity column and therefore doesnt need to be inserted by the insert page.

Thanks again

Grant
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20381476
Okay in that case we can remove all references to Ref and rebuild the query.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<%

Dim MM_editAction

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))

If (Request.QueryString <> "") Then

  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)

End If

 

' IIf implementation

Function MM_IIf(condition, ifTrue, ifFalse)

  If condition = "" Then

    MM_IIf = ifFalse

  Else

    MM_IIf = ifTrue

  End If

End Function

 

 

' read back counter value and convert to integer (number) value

Dim counter

counter = CInt(Request.Form("counterTotal"))

 

' loop through all values in counter and insert for each one

For i = 1 to counter

    Dim MM_editCmd

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

    MM_editCmd.ActiveConnection = MM_camsmith_STRING

    MM_editCmd.CommandText = "INSERT INTO dbo.tableb (field1, field2) VALUES (?, ?)" 

    MM_editCmd.Prepared = true

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, 10, Request.Form("Field1_" & counter)) ' adLongVarChar

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, 10, Request.Form("Field2_" & counter)) ' adLongVarChar

    MM_editCmd.Execute

    MM_editCmd.ActiveConnection.Close

Next

Set MM_editCmd = Nothing

%>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<p>The data was successfully saved into the database!</p>

<p>Time for a beer... :-)</p>

</body>

</html>

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20381590
Hi Rouchie

I have amended the code as suggested and I am getting the same error (see below) when submitting the form to the insert page:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]The parameterized query '(@P1 text,@P2 text)INSERT INTO dbo.tableb (field1, field2) VALUE' expects the parameter '@P1', which was not supplied.

/cms/testinsert.asp, line 33

I am correct to set the form to POST to the insert page?

Once again thanks for your patience and help.

Grant

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20381685
Are you using a stored procedure within the database?
0
 

Author Comment

by:grantballantyne
ID: 20381702
Hi Rouchie

No there are not any stored proceedures
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20381769
>> I am correct to set the form to POST to the insert page?

The first page that lists the values should POST to this new insert page.  Can you set that up and let me know what happens.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:grantballantyne
ID: 20381796
Hi Rouchie

The first page is setup to POST to the insert page but it is still displaying the same error.  Please see the code for the first page attached.

Grant
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<%

Dim tablea

Dim tablea_numRows

Set tablea = Server.CreateObject("ADODB.Recordset")

tablea.ActiveConnection = MM_camsmith_STRING

tablea.Source = "SELECT *  FROM dbo.tablea"

tablea.CursorType = 0

tablea.CursorLocation = 2

tablea.LockType = 1

tablea.Open()

tablea_numRows = 0

 

Dim Repeat1__numRows

Dim Repeat1__index

 

Repeat1__numRows = -1

Repeat1__index = 0

tablea_numRows = tablea_numRows + Repeat1__numRows

%>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

<link href="../includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />

<script src="../includes/common/js/base.js" type="text/javascript"></script>

<script src="../includes/common/js/utility.js" type="text/javascript"></script>

<script src="../includes/skins/style.js" type="text/javascript"></script>

</head>

 

<body>

<form action="testinsert.asp" method="post" name="form1" id="form1">

  <table width="400" border="0">

    <tr>

      <td>Ref      </td>

      <td>Field 1 </td>

      <td>Field 2 </td>

    </tr>

    <% 

Dim counter

counter = 1

While ((Repeat1__numRows <> 0) AND (NOT tablea.EOF)) 

%>

<tr>

  <td><input type="text" name="Ref_<%=counter%>" value="<%=(tablea.Fields.Item("ref").Value)%>" /></td>

  <td><input type="text" name="Field1_<%=counter%>" value="<%=(tablea.Fields.Item("field1").Value)%>" /></td>

  <td><input type="text" name="Field2_<%=counter%>" value="<%=(tablea.Fields.Item("field2").Value)%>" /></td>

</tr> 

<% 

  Repeat1__index=Repeat1__index+1

  Repeat1__numRows=Repeat1__numRows-1

  counter = counter + 1

  tablea.MoveNext()

Wend

%>

    <tr>

      <td>&nbsp;</td>

      <td>&nbsp;</td>

      <td><div align="right">

        <input type="hidden" name="counterTotal" value="<%=counter%>" />

        <input type="submit" name="Submit" value="Submit" />

      </div></td>

    </tr>

 </table>

</form>

</body>

</html>

<%

tablea.Close()

Set tablea = Nothing

%>

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20381813
Hi Rouchie

Could it be something to do with the fact the first page still seems to be posting a value for 'ref' when it is no no longer required?

Grant
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20381849
>> Could it be something to do with the fact the first page still seems to be posting a value for 'ref' when it is no no longer required?

That wouldn't matter.  Although REF would be posted, the second page isn't coded to pick those values up.  You could remove the Ref on the first page though if you wanted.

I've spotted a stupid mistake in the second page.  I was using the value of counter to loop with, rather than the i variable that is set up to count from 1 --> counter

Silly me...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<%

Dim MM_editAction

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))

If (Request.QueryString <> "") Then

  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)

End If

 

' IIf implementation

Function MM_IIf(condition, ifTrue, ifFalse)

  If condition = "" Then

    MM_IIf = ifFalse

  Else

    MM_IIf = ifTrue

  End If

End Function

 

 

' read back counter value and convert to integer (number) value

Dim counter

counter = CInt(Request.Form("counterTotal"))

 

' loop through all values in counter and insert for each one

For i = 1 to counter

    Dim MM_editCmd

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

    MM_editCmd.ActiveConnection = MM_camsmith_STRING

    MM_editCmd.CommandText = "INSERT INTO dbo.tableb (field1, field2) VALUES (?, ?)" 

    MM_editCmd.Prepared = true

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, 10, Request.Form("Field1_" & i)) ' adLongVarChar

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, 10, Request.Form("Field2_" & i)) ' adLongVarChar

    MM_editCmd.Execute

    MM_editCmd.ActiveConnection.Close

Next

Set MM_editCmd = Nothing

%>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<p>The data was successfully saved into the database!</p>

<p>Time for a beer... :-)</p>

</body>

</html>

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20381883
Hi Rouchie

I have amended the code on the insert page as suggested above and I still seem to be getting the error (see below)

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]The parameterized query '(@P1 text,@P2 text)INSERT INTO dbo.tableb (field1, field2) VALUE' expects the parameter '@P1', which was not supplied.

/cms/testinsert.asp, line 33


Grant
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20381933
Another try
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<%

Dim MM_editAction

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))

If (Request.QueryString <> "") Then

  MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)

End If
 

' IIf implementation

Function MM_IIf(condition, ifTrue, ifFalse)

  If condition = "" Then

    MM_IIf = ifFalse

  Else

    MM_IIf = ifTrue

  End If

End Function
 

' read back counter value and convert to integer (number) value

Dim counter

counter = CInt(Request.Form("counterTotal"))

 

' loop through all values in counter and insert for each one

For i = 1 to counter

    Dim MM_editCmd

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

    MM_editCmd.ActiveConnection = MM_camsmith_STRING

    MM_editCmd.CommandText = "INSERT INTO dbo.tableb (field1, field2) VALUES (?, ?)" 

    MM_editCmd.Prepared = true

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, 10, Request.Form("Field1_" & i)) ' adLongVarChar

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, 10, Request.Form("Field2_" & i)) ' adLongVarChar

    MM_editCmd.Execute

    MM_editCmd.ActiveConnection.Close

    Set MM_editCmd = Nothing

Next

%>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<p>The data was successfully saved into the database!</p>

<p>Time for a beer... :-)</p>

</body>

</html>

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20381972
Hi Rouchie,

Same error again im affraid (see below)


Microsoft OLE DB Provider for ODBC Drivers error '80040e14' 
 

[Microsoft][ODBC SQL Server Driver][SQL Server]The parameterized query '(@P1 text,@P2 text)INSERT INTO dbo.tableb (field1, field2) VALUE' expects the parameter '@P1', which was not supplied. 
 

/CMS/testinsert.asp, line 32 

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20382046
Hi Rouchie,

I checked the database and although the insert page displays this error the rows are infact inserted.  

Almost there hopefully
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20382105
Let's scrap DW's code altogether and write it out manually.  See how this goes...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<%

' read back counter value and convert to integer (number) value

Dim counter

counter = CInt(Request.Form("counterTotal"))

 

' loop through all values in counter and insert for each one

If i > 0 then

	For i = 1 to counter

		Dim MM_editCmd

		Dim field1Value

		field1Value = Replace(Request.Form("Field1_" & i), "'", "''")

		Dim field2Value

		field2Value = Replace(Request.Form("Field2_" & i), "'", "''")

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

		MM_editCmd.ActiveConnection = MM_camsmith_STRING

		MM_editCmd.CommandText = "INSERT INTO dbo.tableb (field1, field2) VALUES ('" & field1Value & "','" & field2Value & "')"

		MM_editCmd.Execute

		MM_editCmd.ActiveConnection.Close

		Set MM_editCmd = Nothing

	Next

	%>

	<p>The data was successfully saved into the database!</p>

	<p>Time for a beer... :-)</p>

	<%

Else

	%>

	<p>No post data was found, unable to copy data.</p>

	<%

End If

%>

</body>

</html>

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20382197
Hi Rouchie

I really appreciate your efforts with this.

I changed the insert page to the code you supplied and when I post the form on the first page I get the message below and no data is written to the table.

No post data was found, unable to copy data.

Open in New Window

Grant
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20382329
Okay this implies that no data is being posted from the first page.   Can you go to the first page and change this line of code (near the bottom):
    <input type="hidden" name="counterTotal" value="<%=counter%>" />

to say this:
    <input type="text" disabled="disabled" name="counterTotal" value="<%=counter%>" />

Then run the first page and tell me what the value is at the bottom of the screen in the disabled text field.  Also tell me how many rows appear in the table above it.
0
 

Author Comment

by:grantballantyne
ID: 20382374
Hi Rouchie

Ive amended the code on the first page as suggested and the value that displays is 3 - the number of rows that are displayed is 2 - please see link below
http://www.easiproperty.net/CMS/testdisplay.asp

Thanks

Grant
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20382497
I know why that is.  Because counter increases after displaying each row, therefore after the last row displays, it adds 1 to the total.  We can account for that in the second page really easily.

Change this line in page 2:

   counter = CInt(Request.Form("counterTotal"))

To this:

   counter = CInt(Request.Form("counterTotal")) - 1

Then see what happens.  Note the second page should not say "Open in New window" at the end.  I think you've copied too much text from this page into your code!
0
 

Author Comment

by:grantballantyne
ID: 20382615
Hi Rouchie,

I have amended page 2 as suggested and when the first page is posted the insert page displays:

"No post data was found, unable to copy data."

and no data is inserted into the table?

Grant
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20382724
Let's do some debugging.  Try this new testinsert.asp code, then tell me what it says on screen:


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<%

' read back counter value and convert to integer (number) value

Dim counter

counter = CInt(Request.Form("counterTotal")) - 1

Response.Write("<p>" & counter & " rows were posted.</p>")
 

' loop through all values in counter and insert for each one

If i > 0 then

	For i = 1 to counter

		Dim MM_editCmd

		Dim field1Value

		field1Value = Replace(Request.Form("Field1_" & i), "'", "''")

		Dim field2Value

		field2Value = Replace(Request.Form("Field2_" & i), "'", "''")

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

		MM_editCmd.ActiveConnection = MM_camsmith_STRING

		MM_editCmd.CommandText = "INSERT INTO dbo.tableb (field1, field2) VALUES ('" & field1Value & "','" & field2Value & "')"

		MM_editCmd.Execute

		MM_editCmd.ActiveConnection.Close

		Set MM_editCmd = Nothing

	Next

	%>

	<p>The data was successfully saved into the database!</p>

	<p>Time for a beer... :-)</p>

	<%

Else

	%>

	<p>No post data was found, unable to copy data.</p>

	<%

End If

%>

</body>

</html>

Open in new window

0
 
LVL 25

Accepted Solution

by:
Rouchie earned 500 total points
ID: 20382737
Hang on, spelling mistake...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<!--#include file="../Connections/camsmith.asp" -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<%

' read back counter value and convert to integer (number) value

Dim counter

counter = CInt(Request.Form("counterTotal")) - 1

Response.Write("<p>" & counter & " rows were posted.</p>")
 

' loop through all values in counter and insert for each one

If counter > 0 then

	For i = 1 to counter

		Dim MM_editCmd

		Dim field1Value

		field1Value = Replace(Request.Form("Field1_" & i), "'", "''")

		Dim field2Value

		field2Value = Replace(Request.Form("Field2_" & i), "'", "''")

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

		MM_editCmd.ActiveConnection = MM_camsmith_STRING

		MM_editCmd.CommandText = "INSERT INTO dbo.tableb (field1, field2) VALUES ('" & field1Value & "','" & field2Value & "')"

		MM_editCmd.Execute

		MM_editCmd.ActiveConnection.Close

		Set MM_editCmd = Nothing

	Next

	%>

	<p>The data was successfully saved into the database!</p>

	<p>Time for a beer... :-)</p>

	<%

Else

	%>

	<p>No post data was found, unable to copy data.</p>

	<%

End If

%>

</body>

</html>

Open in new window

0
 

Author Comment

by:grantballantyne
ID: 20382764
Thanks Rouchie

Its definately "time for a beer"

That has worked and is posting to the DB

Cant thank you enough for your patience and help with this

Grant
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20382841
>> Cant thank you enough for your patience and help with this

Likewise.  Have a good weekend. :-)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now