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>
<%@LANGUAGE="VBSCRIPT" codepage="1254"%>
<!--#include file="../Connections/anket13.asp" -->
<%
' *** Edit Operations: declare variables
MM_editAction = CStr(Request("URL")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables
If (CStr(Request("MM_update") <> "" And CStr(Request("MM_recordId") <> "" 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 <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update") <> "" And CStr(Request("MM_recordId") <> "" 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 <> "" Then
FormVal = AltVal
ElseIf (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> 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 <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim pe__MMColParam
pe__MMColParam = "1"
if (Request.QueryString("poll_id" <> "" then pe__MMColParam = Request.QueryString("poll_id"
%>
<%
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
%>
<%
Dim ans__MMColParam
ans__MMColParam = "1"
if (Request.QueryString("poll_id" <> "" then ans__MMColParam = Request.QueryString("poll_id"
%>
<%
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
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
ans_numRows = ans_numRows + Repeat1__numRows
%>
<html>
<head>
<title>BF // Yönetici Ekranları</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
<link rel="stylesheet" href="13mages/ad13.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll="auto" vlink="#333333">
<!--#include file="headerinc.asp" -->
<form name="pe" method="POST" action="<%=MM_editAction%>">
<table width="750" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#CCCCCC">
<tr>
<td align="center" class="hdr"> </td>
<td class="hdr">Anket Değiştirme </td>
</tr>
<tr>
<td align="right" bgcolor="#F7F7F7"><b>Anket :</b></td>
<td bgcolor="#F7F7F7">
<input type="text" name="a" value="<%=(pe.Fields.Item("question".Value)%>">
</td>
</tr>
<tr>
<td align="right" bgcolor="#F7F7F7"><b>Onay :</b></td>
<td bgcolor="#F7F7F7">
<select name="o" >
<option value="1" <%if pe.Fields.Item("onay".Value = 1 Then Response.Write "selected style=""background-color:#000;color:#FFF"""%>>Onay
Var</option>
<option value="0" <%if pe.Fields.Item("onay".Value = 0 Then Response.Write "selected style=""background-color:#000;color:#FFF"""%>>Onay
Yok</option>
</select>
</td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT ans.EOF))
%>
<tr>
<td align="right" bgcolor="#F7F7F7"><b>Cevap
<%=Repeat1__index+1%> :</b></td>
<td bgcolor="#F7F7F7">
<input type="text" name="a<%=Repeat1__index%>" value="<%=(ans.Fields.Item("answer".Value)%>">
<input type="hidden" value="<%=(ans.Fields.Item("answer_id".Value)%>" name="p<%=Repeat1__index%>">
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
ans.MoveNext()
Wend
%>
<tr>
<td align="right" bgcolor="#F7F7F7">
<input type="hidden" name="counter" value="<%=Repeat1__index%>">
</td>
<td bgcolor="#F7F7F7">
<input type="submit" name="Submit" value="Tamam" class="ok">
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="true">
<input type="hidden" name="MM_recordId" value="<%= pe.Fields.Item("poll_id".Value %>">
</form>
</body>
</html>
<%
pe.Close()
%>
<%
ans.Close()
%>
<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
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>
<%@LANGUAGE="VBSCRIPT" codepage="1254"%>
<!--#include file="../Connections/anket13.asp" -->
<%
' *** Edit Operations: declare variables
MM_editAction = CStr(Request("URL")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables
If (CStr(Request("MM_update") <> "" And CStr(Request("MM_recordId") <> "" 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 <> "" And Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Update Record: construct a sql update statement and execute it
If (CStr(Request("MM_update") <> "" And CStr(Request("MM_recordId") <> "" 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 <> "" Then
FormVal = AltVal
ElseIf (Delim = "'" Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''" & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> 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 <> "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim pe__MMColParam
pe__MMColParam = "1"
if (Request.QueryString("poll_id" <> "" then pe__MMColParam = Request.QueryString("poll_id"
%>
<%
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
%>
<%
Dim ans__MMColParam
ans__MMColParam = "1"
if (Request.QueryString("poll_id" <> "" then ans__MMColParam = Request.QueryString("poll_id"
%>
<%
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
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
ans_numRows = ans_numRows + Repeat1__numRows
%>
<html>
<head>
<title>BF // Yönetici Ekranları</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
<link rel="stylesheet" href="13mages/ad13.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scroll="auto" vlink="#333333">
<!--#include file="headerinc.asp" -->
<form name="pe" method="POST" action="<%=MM_editAction%>">
<table width="750" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#CCCCCC">
<tr>
<td align="center" class="hdr"> </td>
<td class="hdr">Anket Değiştirme </td>
</tr>
<tr>
<td align="right" bgcolor="#F7F7F7"><b>Anket :</b></td>
<td bgcolor="#F7F7F7">
<input type="text" name="a" value="<%=(pe.Fields.Item("question".Value)%>">
</td>
</tr>
<tr>
<td align="right" bgcolor="#F7F7F7"><b>Onay :</b></td>
<td bgcolor="#F7F7F7">
<select name="o" >
<option value="1" <%if pe.Fields.Item("onay".Value = 1 Then Response.Write "selected style=""background-color:#000;color:#FFF"""%>>Onay
Var</option>
<option value="0" <%if pe.Fields.Item("onay".Value = 0 Then Response.Write "selected style=""background-color:#000;color:#FFF"""%>>Onay
Yok</option>
</select>
</td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT ans.EOF))
%>
<tr>
<td align="right" bgcolor="#F7F7F7"><b>Cevap
<%=Repeat1__index+1%> :</b></td>
<td bgcolor="#F7F7F7">
<input type="text" name="a<%=Repeat1__index%>" value="<%=(ans.Fields.Item("answer".Value)%>">
<input type="hidden" value="<%=(ans.Fields.Item("answer_id".Value)%>" name="p<%=Repeat1__index%>">
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
ans.MoveNext()
Wend
%>
<tr>
<td align="right" bgcolor="#F7F7F7">
<input type="hidden" name="counter" value="<%=Repeat1__index%>">
</td>
<td bgcolor="#F7F7F7">
<input type="submit" name="Submit" value="Tamam" class="ok">
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="true">
<input type="hidden" name="MM_recordId" value="<%= pe.Fields.Item("poll_id".Value %>">
</form>
</body>
</html>
<%
pe.Close()
%>
<%
ans.Close()
%>
<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
Regards,
TC