Forums

This topic is locked

Update Multiple Records at once

Posted 22 May 2002 12:19:15
1
has voted
22 May 2002 12:19:15 Capuleto Smith posted:
Any one know how to update multiple records at once using just one form and checkboxes ¿?

Regards,

TC

Replies

Replied 22 May 2002 12:51:18
22 May 2002 12:51:18 Some One replied:
I just write this code for a customer multiple update related to standart update

check out th code below..
Important part of code '// Action Time (the solution of your question)

----------------CODE <BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
&lt;%@LANGUAGE="VBSCRIPT" codepage="1254"%&gt;
&lt;!--#include file="../Connections/anket13.asp" --&gt;
&lt;%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request("URL")
If (Request.QueryString &lt;&gt; "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%&gt;
&lt;%
' *** Update Record: set variables

If (CStr(Request("MM_update") &lt;&gt; "" And CStr(Request("MM_recordId") &lt;&gt; "" Then

MM_editConnection = MM_anket13_STRING
MM_editTable = "poll"
MM_editColumn = "poll_id"
MM_recordId = "" + Request.Form("MM_recordId" + ""
MM_editRedirectUrl = "polls.asp"
MM_fieldsStr = "a|value|o|value"
MM_columnsStr = "question|',none,''|onay|none,none,NULL"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|"
MM_columns = Split(MM_columnsStr, "|"

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl &lt;&gt; "" And Request.QueryString &lt;&gt; "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString &lt;&gt; "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%&gt;
&lt;%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update") &lt;&gt; "" And CStr(Request("MM_recordId") &lt;&gt; "" Then

' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),","
Delim = MM_typeArray(0)
If (Delim = "none" Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none" Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none" Then EmptyVal = ""
If (FormVal = "" Then
FormVal = EmptyVal
Else
If (AltVal &lt;&gt; "" Then
FormVal = AltVal
ElseIf (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i &lt;&gt; LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(i) & " = " & FormVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command"
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

'// Action Time
Dim i, xval, soruno, lastq, abcd()

pollno = MM_recordId
For i = 0 To Int(Request.form("counter")

actx = trim(Request.Form("a" & i))
pactx = Request.Form(Cstr("p" & i))
pactx = Int(pactx)

set nq = Server.CreateObject("ADODB.Command"
nq.ActiveConnection = MM_anket13_STRING
nq.CommandText = "UPDATE answer SET poll_id = " & pollno & ", answer = '" & Replace(Trim(actx), "'", "''" &"' WHERE answer_id = " & pactx
nq.CommandType = 1
nq.CommandTimeout = 0
nq.Prepared = true
nq.Execute()
Next

If (MM_editRedirectUrl &lt;&gt; "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%&gt;
&lt;%
Dim pe__MMColParam
pe__MMColParam = "1"
if (Request.QueryString("poll_id" &lt;&gt; "" then pe__MMColParam = Request.QueryString("poll_id"
%&gt;
&lt;%
set pe = Server.CreateObject("ADODB.Recordset"
pe.ActiveConnection = MM_anket13_STRING
pe.Source = "SELECT * FROM poll WHERE poll_id = " + Replace(pe__MMColParam, "'", "''" + ""
pe.CursorType = 0
pe.CursorLocation = 2
pe.LockType = 3
pe.Open()
pe_numRows = 0
%&gt;
&lt;%
Dim ans__MMColParam
ans__MMColParam = "1"
if (Request.QueryString("poll_id" &lt;&gt; "" then ans__MMColParam = Request.QueryString("poll_id"
%&gt;
&lt;%
set ans = Server.CreateObject("ADODB.Recordset"
ans.ActiveConnection = MM_anket13_STRING
ans.Source = "SELECT * FROM answer WHERE poll_id = " + Replace(ans__MMColParam, "'", "''" + ""
ans.CursorType = 0
ans.CursorLocation = 2
ans.LockType = 3
ans.Open()
ans_numRows = 0
%&gt;
&lt;%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
ans_numRows = ans_numRows + Repeat1__numRows
%&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;BF // Yönetici Ekranlar&#305;&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=windows-1254"&gt;
&lt;link rel="stylesheet" href="13mages/ad13.css" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll="auto" vlink="#333333"&gt;
&lt;!--#include file="headerinc.asp" --&gt;
&lt;form name="pe" method="POST" action="&lt;%=MM_editAction%&gt;"&gt;
&lt;table width="750" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#CCCCCC"&gt;
&lt;tr&gt;
&lt;td align="center" class="hdr"&gt;&nbsp;&lt;/td&gt;
&lt;td class="hdr"&gt;Anket De&#287;i&#351;tirme &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="right" bgcolor="#F7F7F7"&gt;&lt;b&gt;Anket :&lt;/b&gt;&lt;/td&gt;
&lt;td bgcolor="#F7F7F7"&gt;
&lt;input type="text" name="a" value="&lt;%=(pe.Fields.Item("question".Value)%&gt;"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td align="right" bgcolor="#F7F7F7"&gt;&lt;b&gt;Onay :&lt;/b&gt;&lt;/td&gt;
&lt;td bgcolor="#F7F7F7"&gt;
&lt;select name="o" &gt;
&lt;option value="1" &lt;%if pe.Fields.Item("onay".Value = 1 Then Response.Write "selected style=""background-color:#000;color:#FFF"""%&gt;&gt;Onay
Var&lt;/option&gt;
&lt;option value="0" &lt;%if pe.Fields.Item("onay".Value = 0 Then Response.Write "selected style=""background-color:#000;color:#FFF"""%&gt;&gt;Onay
Yok&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;%
While ((Repeat1__numRows &lt;&gt; 0) AND (NOT ans.EOF))
%&gt;
&lt;tr&gt;
&lt;td align="right" bgcolor="#F7F7F7"&gt;&lt;b&gt;Cevap
&lt;%=Repeat1__index+1%&gt; :&lt;/b&gt;&lt;/td&gt;
&lt;td bgcolor="#F7F7F7"&gt;
&lt;input type="text" name="a&lt;%=Repeat1__index%&gt;" value="&lt;%=(ans.Fields.Item("answer".Value)%&gt;"&gt;
&lt;input type="hidden" value="&lt;%=(ans.Fields.Item("answer_id".Value)%&gt;" name="p&lt;%=Repeat1__index%&gt;"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
ans.MoveNext()
Wend
%&gt;
&lt;tr&gt;
&lt;td align="right" bgcolor="#F7F7F7"&gt;
&lt;input type="hidden" name="counter" value="&lt;%=Repeat1__index%&gt;"&gt;
&lt;/td&gt;
&lt;td bgcolor="#F7F7F7"&gt;
&lt;input type="submit" name="Submit" value="Tamam" class="ok"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input type="hidden" name="MM_update" value="true"&gt;
&lt;input type="hidden" name="MM_recordId" value="&lt;%= pe.Fields.Item("poll_id".Value %&gt;"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;%
pe.Close()
%&gt;
&lt;%
ans.Close()
%&gt;


<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Ferruh Mavituna : Freelance web developer & designer
Replied 22 May 2002 15:11:50
22 May 2002 15:11:50 Capuleto Smith replied:
I wasn´t really what i was looking for.. but it gives me an idea..

Regards,

TC

Reply to this topic