Replies Back to Article
Multiple Update of Records Part 2
Please note that the link has been changed into:
http://www.ultradev-asp.net/udzone_tutorials/multiple/delete/Default2.asp
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:-)
Is it possible to Update 2 Fields instead of updating 1 (sCatName) like this example. Thanks for your help
I'm usinf ultradev4....and it doesn't appear to be working!
Cheers
Loen
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
<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> </td>
<td> </td>
<td> </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>
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!
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,
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!!!
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
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!!!!!!
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 !
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:
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> </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 ...
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 !
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
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
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......
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.
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
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!!!
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
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>
How can I get this to work if my ID field is varchar? Thanks.
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 =)
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!
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.