Replies Back to Article

Multiple Update of Records Part 2

Example link has changed !
September 28, 2001 by Marcellino Bommezijn

Please note that the link has been changed into:

http://www.ultradev-asp.net/udzone_tutorials/multiple/delete/Default2.asp

The complete code??
December 9, 2001 by Helle M

Will it be possible to download the asp page at some time?? I'm not so hot a code writer, and it's a BIG help to see a hole page with everything to understand it all---
Helle:-)

Update 2 Fields
December 17, 2001 by Evan Scolaro

Is it possible to Update 2 Fields instead of updating 1 (sCatName) like this example. Thanks for your help

How to ...
September 27, 2002 by haj Hou
How to update 2 or more Fields? Can you tell me how to modify the code of your part 2 article ? THX!!
first class!
October 9, 2002 by jake williamson
made a mind bogalingly complicated process dead easy - like the style of writing too. in combination with the multiple delete page it's wicked. thanks, jake
Does this only work with dreamweaver MX
October 16, 2002 by Leon Wilson

I'm usinf ultradev4....and it doesn't appear to be working!

Cheers

Loen

Post Code (not working)
October 18, 2002 by ed hidden

Can you place the code in a ZIP file or something that is downloadable? I'm trying to grab it because I can't get the "form" page to work and I can only see the HTML portion of the code. "no ASP" code is in there when I download it.

Thanks.

Ed

RE: Post Code (not working)
October 19, 2002 by Marcellino Bommezijn

<html>
<head>
<title>UDZONE tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset="iso"-8859-1">
<SCRIPT LANGUAGE="JavaScript">

      function DeleteLinks()
      {
          if (confirm("This will delete the links!  Are you sure you want to do this!?"))
   {
  document.forms[0].action = "Delete2.asp";
  document.forms[0].submit();
   }
      }


      function UpdateLinks()
   {
          if (confirm("This will update the links!  Are you sure you want to do this!?"))
      {
          document.forms[0].action = "Update.asp";
          document.forms[0].submit();
      }
   }
</SCRIPT>
</head>
<body bgcolor="#FFFFFF" text="#000000" >
<form name="form1" method="post">
  <table width="70%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><b>Delete</b></td>
      <td><b>Name</b></td>
      <td><b>Link</b></td>
    </tr>
    <%
Dim iCount
iCount = 0
%>
    <%
While ((Repeat1__numRows <> 0) AND (NOT rsProducts.EOF))
%>
    <tr>
      <td>
        <input type="checkbox" name="Delete" value="<%=(rsProducts.Fields.Item("SCAT").Value)%>">
      </td>
      <td>
        <input type="text" name="<%= (iCount & ".Link") %>" value="<%=(rsProducts.Fields.Item("sCatName").Value)%>">
        <input type="hidden" name="<%= (iCount & ".ID") %>" value="<%=(rsProducts.Fields.Item("SCAT").Value)%>">
      </td>
      <td><%=(rsProducts.Fields.Item("sCatLink").Value)%> </td>
    </tr>
    <%
  repeat1__index="Repeat1__index"+1
  repeat1__numrows="Repeat1__numRows"-1
  rsProducts.MoveNext()
  iCount = iCount + 1  
Wend
%>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3">
        <p>
          <input type="submit" value="Delete Selected Items" onClick="DeleteLinks();" <% If rsProducts.EOF And rsProducts.BOF Then %>disabled<% End If %>>
          <input type="submit" value="Update URL Links" onClick="UpdateLinks();" <% If rsProducts.EOF And rsProducts.BOF Then %>disabled<% End If %>>
          <input type="HIDDEN" name="Count">
        </p>
      </td>
    </tr>
  </table>
</form>
</body>
</html>

RE: Does this only work with dreamweaver MX
October 24, 2002 by Leon Wilson
Sorry, my permissions weren't set up correctly on my local machine.......I have now put it into good practice
Almost...but not quite
November 6, 2002 by Vio Vio

I have the delete page working fine, but I get an error on the update page - Microsoft VBScript runtime (0x800A000D)
Type mismatch: '[string: ""]'
/asp/Update.asp, line 28.

The error is in my loop. Any ideas?

Thanks!

How about using it to update checkbox fields
December 19, 2002 by Carlos Bernal

I have implimented this tutorial but instead of updating a text fields I am updating a checkbox. I am getting the following error when submitting.

Microsoft VBScript runtime error '800a000d'

Type mismatch: '[string: "-1, 0, 1, 2, 3, 4, 5"]'

/payments/confirm-payments/update.asp, line 35

Line 35 on the update page is:

 For iLoop = 0 to iCount

Is the Type mismatch message in reference to that?

-Thanks,

RE: How about using it to update checkbox fields
December 27, 2002 by Carlos Bernal

I figured out what I did wrong...I placed the

<input type="HIDDEN" name="Count" value="<%=iCount - 1 %>">

within the repeat region...I now placed it next to the Update button---works perfectly!!!

Only Updates 1st Record
January 20, 2003 by Rick McConnell

Hi, I am having a nightmare trying to get this code to work.  It only updates the first record in the database.  Any other changes are not made.  Could you give me an indication of the code I should be lookin at.  I have been through it many times and the pages I'm workin on are massive.  I'm sure it's something I've done wrong but an idea of what I should be lookin at would be much appreciated.

Thanks
Rick

Cannot make it work
February 5, 2003 by Igor Kravchenko

I spend a lot of time trying to make it work.  Could anybody help me please?  The first page works and on the second page it updates records and then gives me:
**************************************************************
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.
/mas/EZAudit/test.asp, line 19
**************************************************************

My code is:
**************************************************************
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/EZAudit.asp" -->
<%
Response.Buffer = True
Dim iCount
iCount = Request.Form("Count")
Dim strLink, strID
Dim strSQL
Dim Command1
set Command1 = Server.CreateObject("ADODB.Connection")
Command1.ConnectionString = MM_EZAudit_STRING
Command1.Open
Dim iLoop
For iLoop = 0 to iCount
strLink = Request(iLoop & ".Link")
strID = Request(iLoop & ".ID")
strSQL = "UPDATE Installed SET Display = '" & strLink & " ' " &_
" WHERE Num = " & strID
Command1.Execute strSQL
Next
Command1.Close
Set Command1 = Nothing
Response.Write "Links were updated ! One moment..."
%>
**************************************************************

Could anybody tell me what am I doing wrong?  Pleeeeeese!!!!!!

Syntax error in UPDATE statement
May 30, 2003 by George Drakakis
Marcellino = Genius
June 19, 2003 by Ben Wells
Thank you Marcellino. An impressive piece of code that has helped me tremendously. I completed the Multi Delete section fairly quickly but ran into a few problems on the update part. For those of you who are copying off the page into DMX BE CAREFUL. Check the coding thoroughly for extra spaces. I found 3 random spaces that shouldn?t have been there which caused me to rip my hair out for a few hours. Shame the Code Snippet and Live Demo links weren't working. If anyone would like a working version of this tutorial you can download the asp files from... http://madnightsout.no-ip.com/asp/multi_update_delete.zip Thanks Len (Poor Leno)
RE: Marcellino = Genius
June 19, 2003 by Marcellino Bommezijn

Well not completely....the sample URL isn't working for a while now :-)

Soon i will re-organize some of my demos....i promise !

Hope you got some hair left !

Missing Operator
July 11, 2003 by Peter Wiseman

Hi,

 

I've tried several examples of the `delete/update multiple record' scripts.

The `delete' code worked first time, however no matter what I try I get the following error on the `update' page:

  • Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'ID ='.
    /pottery/AdminUpdateProducts.asp, line 20

    Here is the code from my page:

  • <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="Connections/pottery.asp" -->
    <%
    Response.Buffer = True
    Dim iCount
    iCount = Request.Form("Count")
    Dim strLink, strID
    Dim strSQL
    Dim Command1
    set Command1 = Server.CreateObject("ADODB.Connection")
    Command1.ConnectionString = MM_Pottery_STRING
    Command1.Open
    Dim iLoop
    For iLoop = 0 to iCount
    strLink = Request(iLoop & ".Link")
    strID = Request(iLoop & ".ID")
    'To update
    strSQL = "UPDATE Products2001  SET price = '" & strLink & "'" &_
    " WHERE ID = " & strID
    Command1.Execute strSQL
    Next
    Command1.Close
    Set Command1 = Nothing

    Response.Write "Prices were updated, you will be directed back to the Gallery Administration Page ..."

    %>
    <html>
    <head>
    <title>Update Product Prices</title>
    <meta http-equiv="Content-Type" content="text/html; charset="iso"-8859-1">
    <meta http-equiv="refresh" content="2;URL=AdminSalesGallery.asp">
    </head>

    <body bgcolor="#FFFFFF" text="#000000" leftmargin="2" topmargin="25">
    <br>
    <p>&nbsp;</p>
    </body>
    </html>

    Is the problem on this page or could it be on the page with the form?

    Any help would be most appreciated ...

    RE: Missing Operator
    July 12, 2003 by Marcellino Bommezijn
    Did you correctly added the instructions as mentioned in step 3: Associating the ID to the Name column ?
    demo + completed pages
    July 12, 2003 by Marcellino Bommezijn

    The demo is on-line again and the completed pages (update + delete functionality) are available for download.

    Hope this helps everybody that had some trouble with getting this too work !

     

    RE: RE: Missing Operator
    July 13, 2003 by Peter Wiseman

    Hi Marcellino,

    Thanks for the reply ... I went back and looked at the step 3 bit and - yup, it was incorrect ...

    I hadn't put the <%%> bits around the (iCount & ".Link") bit ... :-(

    Sheesh ... well it works well now ... onto the next problem  :-)

    Regards

    PW

    Need HELP
    July 29, 2003 by To Ken

    Please,

    I made all what You have said.....but....
    I have more text fields. Well I figured it how You have donne this but I'm not sure what i must write when i want to have more fields for update...example:

    strSQL = "UPDATE tblPif SET Naziv = ' " & strNaziv & " ' AND Cijena = ' " & strCijena & " ' AND Promet = ' " & strPromet & " ' AND RedniBroj =  ' " & strPoredak & " ' AND Pokazi =  ' " & strPokazi & " ' " & " WHERE pifID = " & strID

    This can not work?!

    I also tryed with comma:

    strSQL = "UPDATE tblPif SET Naziv = ' " & strNaziv & " ', Cijena = ' " & strCijena & " ', Promet = ' " & strPromet & " ', RedniBroj =  ' " & strPoredak & " ', Pokazi =  ' " & strPokazi & " ' " &_
    " WHERE pifID = " & strID

    Please help ME

    Also one of this fields is checkbox

    Allready solved
    July 29, 2003 by To Ken
    Allready solved...problems with checkbox
    How to update checkbox?
    July 30, 2003 by To Ken

    Please,

    I have also checkbox for updating. But im getting this error:

    Error Type:
    Microsoft JET Database Engine (0x80040E07)
    Data type mismatch in criteria expression.

    I work with MS ACCESS. How to update checkbox?!
    Please need it badly......

    RE: How to update checkbox?
    July 30, 2003 by Marcellino Bommezijn

    Make use of a standard update behavior within DMX which includes a checkbox and take a look at the syntax/code within the update statement that DMX creates. This should help you how to setup the manual page for multiple update with a checkbox included.

     

    RE: RE: How to update checkbox?
    July 30, 2003 by To Ken

    I tried to figured it but..... ;(

    I saw only difference is:
     "checkbox|none,Yes,No| ..." for Access and
     "checkbox|null,1,0| ..." for 1 or 0
    Im not sure what i have to do with this.You have do that in other way.

    If you can explain i will appreciate that ;)

    Thanks in advance

    THIS CODE IS A GOD-SEND!!!!!!!!!!!!!!!!
    December 12, 2003 by Vince Vaughn

    I've been trying like crazy to build a learning management system that (among other things) tracks user's learning records.  The only thing hanging me up was how to submit student grades with one submit button from a dynamically generated student roster.  I came close but no cigar.  UNTIL I stumbled accross this code.  It works BEAUTIFULLY!!!

    THANK YOU SO MUCH!!!

    RE: THIS CODE IS A GOD-SEND!!!!!!!!!!!!!!!!
    January 29, 2004 by Tulio Murillo

    This tutorial is amazing!!!  No book out there will teach you how to acomplish multiple updates.  THANK YOU SO MUCH!!!

    Tulio Murillo

    New Jersery, USA

    Major Flaw?
    February 21, 2004 by Eric McGuire
    Major Flaw?
    February 21, 2004 by Eric McGuire
    Can't update record when using an apostrophe...
    February 23, 2004 by Zeus Maverick
    Yowzers!! This code is great but the text field I want to update will often contain an apostrophe...which won't work with this.  When I enter an apostrophe in the text field and hit the update button, I get an error due to trying to pass a single apostrophe in my string.  If I enter a double apostrophe instead of a single one (' '), then the update page displays correctly and only one apostrophe is added to the database.  I have seen fixes for the apostrophe problem when using a single update page but how is it done when trying to pass the data to a second page like in this code????  When the working example is up and running, you can see this error by adding an apostrophe to the text field and then clicking the update button.  Any help would be greatly appreciated!!!! Thanks!!!
    Multiple Insert
    May 3, 2004 by philip williams

    Both the update & delete code is fantastic. I been have trying for a week or so (on and off) to develop a similar function but perform a multiple record insert into a single table.

    My first page retrieves student details and places the student id into a dynamic text field. This is then sent to the 2nd page where, if the checkbox for the student is checked it is inserted in the table. I am using a For stmt (as per multiple update code) in addition an IF stmt to insert if the checkbox is ticked .

    The problem I am encounting is that for each student ticked I am getting a duplicate record inserted into the table. I am assuming it is to do with the construction of my For & If stmts. Can anyone help?

     

    Code Below for the troublesome page (apologies for the length of posting)

     

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
    <!--#include file="../Connections/min.asp" -->
    <%
    Response.Buffer = True
    Dim Counting
    Counting = Request("Counter")
    Response.Write(Counting)

    Dim strID
    Dim strCheck
    Dim strSQL
    Dim iLoop

    Dim Command1
    set Command1 = Server.CreateObject("ADODB.Connection")
    Command1.ConnectionString = MM_Min_STRING
    Command1.Open

    For iLoop = 0 to Counting
    strCheck = Request(iLoop & ".Update")
    if strCheck = "Update" Then
    strID = Request(iLoop & ".ID")
    strSQL = "INSERT INTO attendance (student_no) VALUES ('"&strID&"')"
    Command1.Execute strSQL
    End If
    Next
    Command1.Close
    Set Command1 = Nothing
    %>


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

    <body>
    Update Page
    </body>
    </html>

    ID fieldtype = varchar
    May 27, 2004 by Scott Iwamoto

    How can I get this to work if my ID field is varchar?   Thanks.

    Fixed it
    May 27, 2004 by Scott Iwamoto

    Sorry I just realized that it is counting the records.  doh!  The problem was that I had the hiddenfield Count in the repeating region thus the type mismatch error. 

    Awesome tutorial .... Thx =)

    RE: RE: RE: How to update checkbox?
    January 10, 2005 by Jennifer Glinski

    I have the same question about updating multiple records using a checkbox.  How do you incorporate "checkbox|null,1,0| into this example.  I couldn't find any posted solutions and this is the only place I have found someone having the same problem as me.  Thanks for any assistance!

    Fantastis Tutorial and download
    January 24, 2005 by peter Jarvis
    I am a designer, not a programmer. I had two order tables in my database that were linked in the access databse and managed to amend the delete page so that it deleted out of both tables, this is brilliant, so simple to ammend and tailor. Job well done :)
    OK Sorted - Read below for solutions.
    August 3, 2006 by Kevin Dandridge
    Ok I seriously had problems getting it sorted out and finally with perseverence I got it.
    OK Sorted - Read below for solutions.
    August 3, 2006 by Kevin Dandridge
    Ok I seriously had problems getting it sorted out and finally with perseverence, and tweak after tweak and some 20 hours later I got it. (sorry this submits on "Enter" Keypress) I can't even begin to mention the teething problems so I thought I'd post the zip file somewhere. It does work on Windows XP Pro, just drop it into your wwwroot and it should run no problem. All files are included. Just point your browser to form.asp in the admin folder. I thought I'd mention that it updates 2 columns too :). I probably wont be able to help with any questions as I can't code to save my butt :). Anyway good luck and enjoy. Here is the zip file: http://mysite.mweb.co.za/residents/natcon/update_multiple.zip
    not redirect via js
    August 16, 2007 by cumap cumap
    I don't get it but the javascript redirect function does not take me to the update.asp page.  Any idea?
    RE:not direct via js
    August 16, 2007 by cumap cumap

    Nevermind, I realized forms[0] is incorrect and I changed it to the correct form name and the function is working now.

    Thank you for the great batch update code.
     

    Useful discussion
    February 10, 2016 by User
    Useful discussion - Just to add my thoughts , if people requires to merge PDF files , my kids merged a service here http://www.altomerge.com/