Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 15
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    174

    Aggiungo campo su multi record?

    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"> &lt;=== This would be hidden





    <input type="submit" name="Submit" value="Update">
    </form>
    </body>
    </html>
    <%
    Recordset1.Close()
    Set Recordset1 = Nothing
    %>
    Pattaya

  2. #2
    ti dà errore. ottima informazione

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    174
    scusami...

    Microsoft JET Database Engine error '80040e14'

    Syntax error in UPDATE statement.

    /xxx.asp, line 19
    Pattaya

  4. #4
    quindi l'errore è nell'update. fatti stampare a video la query di aggiornamento e controllala

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    174
    Mi da questo..
    sempre se so fare una stampa query..

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Inetpub\webs\xxx\mdb-database\xxx.mdb;Persist Security Info=False
    Pattaya

  6. #6
    quella è la connessione. la query è quella con l'update

  7. #7
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    174
    se faccio così:

    Response.Write(commUpdate)
    Response.End()
    objRs.Open commUpdate, objConn


    mi da una pagina bianca...?
    Pattaya

  8. #8
    tutto te se deve da di'

    codice:
    ...
    commUpdate.ActiveConnection = strConnection
    Dim sSql
    sSql =  "UPDATE TestTable SET RecText = '" & strText & "', RecNum = " & intNum & ", RecNex = " & intNex & " WHERE RecID = " & arrRecIDs(intCount)
    Response.Write "maGGica SQL...: " & sSql
    Response.Flush
    commUpdate.CommandText = sSql
    commUpdate.CommandType = 1
    ...
    that easy!

  9. #9
    Utente di HTML.it
    Registrato dal
    Jun 2007
    Messaggi
    174
    Ho provato ad aggiornare dal form i primi 2 record di tutti i campi:

    errore è questo

    SQL:UPDATE TestTable SET RecText = 'aaa', RecNum = aaa, RecNex = aaa WHERE RecID = 1
    Microsoft JET Database Engine error '80040e10'

    No value given for one or more required parameters.

    /xxx.asp, line 27
    Pattaya

  10. #10
    controlla i nomi dei campi
    controlla il tipo di campo
    controlla gli apici

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.