judsonmusic
asked on
update multiple records at once! please help me out!
Here is the problem:
When using the repeat region on dreamweaver, It wont allow me to update multiple record. I can see them, I can edit them, but when I hit submit, nothing happens.
here is my page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/nelson.a sp" -->
<%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariabl es("SCRIPT _NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request. QueryStrin g)
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") ) = "form1" And CStr(Request("MM_recordId" )) <> "") Then
MM_editConnection = MM_nelson_STRING
MM_editTable = "dbo.answerstable"
MM_editColumn = "answersID"
MM_recordId = "" + Request.Form("MM_recordId" ) + ""
MM_editRedirectUrl = "updatecomplete.asp"
MM_fieldsStr = "answerstext|value"
MM_columnsStr = "answers|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_field s(MM_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 MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1)," ,")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","'' ") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_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.ActiveConnectio n = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnectio n.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editR edirectUrl )
End If
End If
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB .Recordset ")
Recordset1.ActiveConnectio n = MM_nelson_STRING
Recordset1.Source = "SELECT * FROM dbo.answerstable"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 20
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<%=MM_editAction%> ">
<table width="100%" border="1">
<tr>
<td width="16%">ID</td>
<td width="84%">Answer</td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr>
<td><%=(Recordset1.Fields. Item("answ ersID").Va lue)%></td >
<td><label>
<input name="answerstext" type="text" id="answerstext" value="<%=((Recordset1.Fie lds.Item(" answers"). Value))%>" size="120" />
</label></td>
</tr>
<%
Repeat1__index=Repeat1__in dex+1
Repeat1__numRows=Repeat1__ numRows-1
Recordset1.MoveNext()
Wend
%>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="Submit" />
</label></td>
<td> </td>
</tr>
</table>
<p> </p>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("an swersID"). Value %>">
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
-------------------------- ---------- ---------- -
Can someone tell me what i can do to fix this where it will update multiple records at one time???
Please be specific based on my code.
Judson
When using the repeat region on dreamweaver, It wont allow me to update multiple record. I can see them, I can edit them, but when I hit submit, nothing happens.
here is my page:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/nelson.a
<%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariabl
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.
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")
MM_editConnection = MM_nelson_STRING
MM_editTable = "dbo.answerstable"
MM_editColumn = "answersID"
MM_recordId = "" + Request.Form("MM_recordId"
MM_editRedirectUrl = "updatecomplete.asp"
MM_fieldsStr = "answerstext|value"
MM_columnsStr = "answers|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_field
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")
' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),"
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_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
MM_editCmd.ActiveConnectio
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnectio
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editR
End If
End If
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB
Recordset1.ActiveConnectio
Recordset1.Source = "SELECT * FROM dbo.answerstable"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 20
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<%=MM_editAction%>
<table width="100%" border="1">
<tr>
<td width="16%">ID</td>
<td width="84%">Answer</td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr>
<td><%=(Recordset1.Fields.
<td><label>
<input name="answerstext" type="text" id="answerstext" value="<%=((Recordset1.Fie
</label></td>
</tr>
<%
Repeat1__index=Repeat1__in
Repeat1__numRows=Repeat1__
Recordset1.MoveNext()
Wend
%>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><label>
<input type="submit" name="Submit" value="Submit" />
</label></td>
<td> </td>
</tr>
</table>
<p> </p>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("an
</form>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
--------------------------
Can someone tell me what i can do to fix this where it will update multiple records at one time???
Please be specific based on my code.
Judson
Always use this,
Request.Form("MM_recordId" )
instead of this,
Request("MM_recordId")
Request.Form("MM_recordId"
instead of this,
Request("MM_recordId")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, number one, where would I put this code, and number 2 what if I did use asp.net???
How would I do it then????
Thanks
Judson
How would I do it then????
Thanks
Judson
The first block replaces the block you have in the code you posted.
To make things simpler and to break the code down, I would get this page to post to a new page rather than back to itself. So I'd change this:
<form id="form1" name="form1" method="POST" action="<%=MM_editAction%> ">
to this:
<form id="form1" name="form1" method="POST" action="updatepage.asp">
The second block of code then goes in updatepage.asp, but it will need expanding to include success/failure messages. If you are unsure of how to do this then it might be best tracking down some lessons on how to write the code yourself, as its a bit of a minefield.
As for ASP.NET, the whole approach to writing pages is different, so there's lots of new things to be aware of. The 4Guys' tutorials are what I used to start doing this, although you will need to download the .NET framework from microsoft to run ASP.NET on your computer.
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx
To make things simpler and to break the code down, I would get this page to post to a new page rather than back to itself. So I'd change this:
<form id="form1" name="form1" method="POST" action="<%=MM_editAction%>
to this:
<form id="form1" name="form1" method="POST" action="updatepage.asp">
The second block of code then goes in updatepage.asp, but it will need expanding to include success/failure messages. If you are unsure of how to do this then it might be best tracking down some lessons on how to write the code yourself, as its a bit of a minefield.
As for ASP.NET, the whole approach to writing pages is different, so there's lots of new things to be aware of. The 4Guys' tutorials are what I used to start doing this, although you will need to download the .NET framework from microsoft to run ASP.NET on your computer.
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx
The built-in behaviors in DW will not update multiple records at once. You either need to hand-code this or buy a third-party extension that will write the code for you.
Unfortunately, I don't do ASP, so I can't help you with the code. Rouchie does and he should be checking this question at some point...
If you want to take a crack at doing it yourself, here are some articles that may help:
http://charon.co.uk/content.aspx?CategoryID=27&ArticleID=41
http://www.drdev.net/article01.htm
http://www.drdev.net/article11.asp
If you want to throw money at the problem:
http://www.felixone.it/
http://www.interaktonline.com/Products/Bundles/Kollection/Features/Details/Edit+multiple+records+at+the+same+time.html?id_ftr=265