Questo è il codice che ho trovato ed adattato aggiungendo il campo "RecNex" ma come non detto, mi da errore.
In rosso quello che ho modificato ed aggiunto.
Ho diviso tutto in colori perchè spero che sia più chiaro per arrivare ad una soluzione.
Grazie in anticipo.
<%
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("mdb-database/TestDB.mdb") & ";Persist Security Info=False"
If Request("Submit") <> "" Then
intRecIDs = Replace(Request("hidRecIDs"), "*", "") ' remove all the asterisks, to create a list like this: 2, 5, 8, 9 etc.
arrRecIDs = Split(intRecIDs, ", ") ' Create an array, wich will contain just the IDs of the records we need to update
For intCount = 0 to Ubound(arrRecIDs)' Loop trough the array
strText = Replace(Request("txtText" & arrRecIDs(intCount)), "'", "''")
intNum = Replace(Request("txtNum" & arrRecIDs(intCount)), "'", "''")
intNex = Replace(Request("txtNex" & arrRecIDs(intCount)), "'", "''")
set commUpdate = Server.CreateObject("ADODB.Command")
commUpdate.ActiveConnection = strConnection
commUpdate.CommandText = "UPDATE TestTable SET RecText = '" & strText & "', RecNum = " & intNum & ", RecNex = " & intNex & " WHERE RecID = " & arrRecIDs(intCount)
commUpdate.CommandType = 1
commUpdate.CommandTimeout = 0
commUpdate.Prepared = true
commUpdate.Execute()
Next
strMessage = intCount & " Records Updated"
Response.Redirect("MultiUpdateDemo.asp?Message=" & strMessage)
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = strConnection
Recordset1.Source = "SELECT RecID, RecText, RecNum, RecNex FROM TestTable"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<html>
<head>
<title>Update Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
// When the value in a textfield is changed, notice the onChange="RecUpdate ('<%= intRecID %>')"
// on each of the textfields, the value of the Record ID associated with that field
// is passed to the RecUpdate function. First the value is surounded with 2 asterisks e.g. *6*
// This is so that *1* can be distinguished from *10*, *11* etc.
function RecUpdate(RecID){
var ThisID = "*" + (RecID) + "*"
if (document.form1.hidRecIDs.value == ""){ // If the hidden field is empty
document.form1.hidRecIDs.value = (ThisID) // Store the value in the hidden field (hidRecIDs) as it is.
}
if (document.form1.hidRecIDs.value != ""){ // If the hidden field isn't empty
var str = document.form1.hidRecIDs.value; // Store the contents of the hidden field in the variable str
var pos = str.indexOf(ThisID); // Search str to see if this RecID is allready in it.
if (pos == -1) { // If the position returned is -1 it isn't allredy in there,
document.form1.hidRecIDs.value = document.form1.hidRecIDs.value + ", " + (ThisID)
} // so add ", " and this ID to what is already in hidRecIDs
} // to create a list like this *2*, *5*, *8* etc.
}
//-->
</script>
</head>
<body>
<%= Request.QueryString("Message") %>
<form name="form1" method="post" action="MultiUpdateDemo.asp">
<table width="500" border="0" cellpadding="1" cellspacing="6" bgcolor="#F0F0F0">
<tr>
<td width="37">RecID</td>
<td width="217">RecText</td>
<td width="226">RecNum</td>
<td width="226">RecNex</td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<% intRecID =(Recordset1.Fields.Item("RecID").Value) ' Store the current RecordID in a variable %>
<tr>
<td nowrap> <%= intRecID %><input name="hidRecID <%= intRecID %>" type="hidden" value=" <%= intRecID %>" size="5"></td>
<td nowrap><input name="txtText<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecText").Value)%>" size="20"></td>
<td nowrap><input name="txtNum<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecNum").Value)%>" size="20"></td>
<td nowrap><input name="txtNex<%= intRecID %>" type="text" onChange="RecUpdate('<%= intRecID %>')" value="<%=(Recordset1.Fields.Item("RecNex").Value) %>" size="20"></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
</table>
<input name="hidRecIDs" type="text" size="40"> <=== This would be hidden
<input type="submit" name="Submit" value="Update">
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

Rispondi quotando
