|
| |
|
|
reem_04
Posts: 13 Joined: 10/29/2007 Status: offline
|
ADDING MULITPLE RECORD in ONE FORM ASP - 10/29/2007 6:50:38
Hi ALL! I am trying to design inspection form that have different question, two date, corrective active , yes, no and n/a. Forms I wish to design contain all of 30 question plus those filed and insert more than one record. I code I use is the following but it save all of the data in one record in database please help me <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/intraweb.asp" -->
<%
' *** 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.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editConnection = MM_intraweb_STRING
MM_editTable = "dbo.dept_safety_Inspection_report_g"
MM_editRedirectUrl = "new_conf.asp"
MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value"
MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',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_fields(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
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tableValues
Dim MM_dbValues
If (CStr(Request("MM_insert")) <> "") Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
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_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<!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>
<link href="stylesindex.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="1024" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td background="../images/Radiology2_02.jpg"><form action="<%=MM_editAction%>" method="post" name="form1" id="form1">
<table align="center" width="879">
<tr valign="baseline">
<td align="center" nowrap="nowrap" class="style2" width="50"><b>Item
no.</b></td>
<td class="style3" width="309" align="center"><b>Item</b></td>
<td align="center" width="50">
<p align="center">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Yes- No -N/A</font></span></td>
<td align="center" width="173">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Corrective Action</font></span></td>
<td align="center" width="134">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Responsibility</font></span></td>
<td align="center" width="103">
<span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt">
Target Date</font></span></td>
<td align="center" width="88">
<span style="font-weight: 700">
<font face="Verdana" style="font-size: 8pt">Date Completed</font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.1"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q1</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.2"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q2</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.3"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q3</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr>
<td align="right" nowrap="nowrap" class="style2" width="50" height="75">
<p align="center">
<input type="text" name="Item_num" size="4" value="1.4"></td>
<td class="style3" width="309" height="75">
<textarea rows="4" name="item" cols="36">q4</textarea></td>
<td align="left" width="50"><font face="Verdana" style="font-size: 8pt">
<select size="3" name="G_Yes">
<option selected value="Yes">Yes</option>
<option value="N/A">N/A</option>
<option value="No">No</option>
</select> </font> </td>
<td align="left" width="173"><font face="Verdana" style="font-size: 8pt">
<textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td>
<td align="left" width="134"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Responsibility" size="20"></font></td>
<td align="left" width="103"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Target_Date" size="19"></font></td>
<td align="left" width="88"><font face="Verdana" style="font-size: 8pt">
<input type="text" name="Date_Completed" size="16"></font></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"><div align="left"></div>
<p align="center"><input type="submit" value="Insert record"/>
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
</td>
</tr>
</table>
</body>
</html> thanks alot
< Message edited by Spooky -- 10/29/2007 14:04:26 >
|
|
|
|
William Lee
Posts: 1080 Joined: 1/25/2002 From: Singapore Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/30/2007 6:32:03
Your insert statement occurs only once and that is outside the 2nd For..Next loop. Another thing to check is that MM_i is not initialised after the first For..Next
_____________________________
William Lee
|
|
|
|
William Lee
Posts: 1080 Joined: 1/25/2002 From: Singapore Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/30/2007 7:08:44
Try this and we act on the results that are returned: ' *** Insert Record: construct a sql insert statement and execute it Dim MM_tableValues Dim MM_dbValues Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = MM_editConnection If (CStr(Request("MM_insert")) <> "") Then ' create the sql insert statement MM_tableValues = "" MM_dbValues = "" Response.write MM_i 'to test value for MM_i before it goes into the For..Next Loop MM_i=0 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_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End If MM_tableValues = MM_tableValues & MM_columns(MM_i) MM_dbValues = MM_dbValues & MM_formVal MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")" Response.write MM_editQuery ' see what the SQL statement is like If (Not MM_abortEdit) Then ' execute the insert MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute End if Next MM_editCmd.ActiveConnection.Close If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If %>
< Message edited by William Lee -- 10/30/2007 20:07:58 >
_____________________________
William Lee
|
|
|
|
reem_04
Posts: 13 Joined: 10/29/2007 Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 1:31:36
hi there thanks for you fast reply as usual here is your request number 78 is ther line where the code giving there errors <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="../../Connections/intraweb.asp" --> <% ' *** 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.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString) End If ' boolean to abort record edit MM_abortEdit = false ' query string to execute MM_editQuery = "" %> <% ' *** Insert Record: set variables If (CStr(Request("MM_insert")) = "form1") Then MM_editConnection = MM_intraweb_STRING MM_editTable = "dbo.dept_safety_Inspection_report_g" MM_editRedirectUrl = "new_conf.asp" MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value" MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',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_fields(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 %> <% ' *** Insert Record: construct a sql insert statement and execute it Dim MM_tableValues Dim MM_dbValues Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = MM_editConnection If (CStr(Request("MM_insert")) <> "") Then ' create the sql insert statement MM_tableValues = "" MM_dbValues = "" Response.write MM_i ' **** to test value for MM_i before it goes into the For..Next Loop MM_i=0 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_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End If MM_tableValues = MM_tableValues & MM_columns(MM_i) MM_dbValues = MM_dbValues & MM_formVal MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")" Response.write MM_editQuery ' see what the SQL statement is like If (Not MM_abortEdit) Then ' execute the insert MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute End if next MM_editCmd.ActiveConnection.Close If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If %> <!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> <link href="stylesindex.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="1024" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td background="../images/Radiology2_02.jpg"><form action="<%=MM_editAction%>" method="post" name="form1" id="form1"> <table align="center" width="879"> <tr valign="baseline"> <td align="center" nowrap="nowrap" class="style2" width="50"><b>Item no.</b></td> <td class="style3" width="309" align="center"><b>Item</b></td> <td align="center" width="50"> <p align="center"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Yes- No -N/A</font></span></td> <td align="center" width="173"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Corrective Action</font></span></td> <td align="center" width="134"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Responsibility</font></span></td> <td align="center" width="103"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Target Date</font></span></td> <td align="center" width="88"> <span style="font-weight: 700"> <font face="Verdana" style="font-size: 8pt">Date Completed</font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.1"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q1</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.2"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q2</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.3"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q3</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.4"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q4</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr valign="baseline"> <td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"> </td> </tr> <tr valign="baseline"> <td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"><div align="left"></div> <p align="center"><input type="submit" value="Insert record"/> </td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> </td> </tr> </table> </body> </html>
< Message edited by reem_04 -- 10/31/2007 1:38:09 >
|
|
|
|
William Lee
Posts: 1080 Joined: 1/25/2002 From: Singapore Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 1:53:16
Make sure the include file is correct path. Are you executing the modified asp page in the same folder as the original asp page? What is the value of MM_Intraweb_String? This is the value given to MM_EditConnection and giving error? Can you check if this is line 78? What values are being returned for the 2 response.write statement, if it get that far?
_____________________________
William Lee
|
|
|
|
reem_04
Posts: 13 Joined: 10/29/2007 Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 3:15:16
Make sure the include file is correct path ....has been check thanks Are you executing the modified asp page in the same folder as the original asp page? .... yes What is the value of MM_Intraweb_String? .... is the conection for path of database This is the value given to MM_EditConnection and giving error? Can you check if this is line 78? .... yes this the line where it give me error MM_editCmd.ActiveConnection = MM_editConnection What values are being returned for the 2 response.write statement, if it get that far? .... i am using fornt page for the asp code i don't know how to track the code in it but it give me this error ADODB.Command error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /inside/Dept_Safety_Inspection_Report/admin_prv_copy(1).asp, line 78 [/quote]
|
|
|
|
William Lee
Posts: 1080 Joined: 1/25/2002 From: Singapore Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 3:21:37
Do you have adovbs.inc as include in your project? This is a file of ADO constants.
_____________________________
William Lee
|
|
|
|
reem_04
Posts: 13 Joined: 10/29/2007 Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 3:27:41
Do you have adovbs.inc as include in your project? ..no i don't have file in the form with this ext. i only have include file for connection <!--#include file="../../Connections/intraweb.asp" --> .. This is a file of ADO constants. [/quote]
|
|
|
|
William Lee
Posts: 1080 Joined: 1/25/2002 From: Singapore Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 3:39:28
quote:
ORIGINAL: reem_04 What is the value of MM_Intraweb_String? .... is the conection for path of database This is the value given to MM_EditConnection and giving error? Can you check if this is line 78? .... yes this the line where it give me error MM_editCmd.ActiveConnection = MM_editConnection the clue is in the connection. Are you able to provide the contents of that include file but censor the password and usrname and paths?
_____________________________
William Lee
|
|
|
|
William Lee
Posts: 1080 Joined: 1/25/2002 From: Singapore Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 5:33:50
OK, it seems if you want to execute the INSERT multiple times, you really need to create and establish a Connection to your db. The original script is good for ONE specific, single query. I recommend the following amendments to my previous changes: Put these inside the <%...%> of the include file, at the end set conn=Server.CreateObject("ADODB.Connection") conn.ConnectionString=MM_intraweb_String conn.Open Then comment out the line MM_editConnection=MM_intraweb_STRING as conn will be used instead. Next change line 78 to MM_editCmd.ActiveConnection=conn Finally, change MM_editCmd.ActiveConnection.Close to conn.close. This is right at the end, when the code exits the For..Next loop. For good practice, set all Connections to Nothing at the end. Set conn=Nothing <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="../../Connections/intraweb.asp" --> <% ' *** 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.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString) End If ' boolean to abort record edit MM_abortEdit = false ' query string to execute MM_editQuery = "" %> <% ' *** Insert Record: set variables If (CStr(Request("MM_insert")) = "form1") Then ' *** MM_editConnection = MM_intraweb_STRING ---comment out this line MM_editTable = "dbo.dept_safety_Inspection_report_g" MM_editRedirectUrl = "new_conf.asp" MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value" MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',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_fields(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 %> <% ' *** Insert Record: construct a sql insert statement and execute it Dim MM_tableValues Dim MM_dbValues Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = conn '*** MM_editConnection If (CStr(Request("MM_insert")) <> "") Then ' create the sql insert statement MM_tableValues = "" MM_dbValues = "" Response.write MM_i ' **** to test value for MM_i before it goes into the For..Next Loop MM_i=0 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_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End If MM_tableValues = MM_tableValues & MM_columns(MM_i) MM_dbValues = MM_dbValues & MM_formVal MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")" Response.write MM_editQuery ' see what the SQL statement is like If (Not MM_abortEdit) Then ' execute the insert MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute End if next conn.Close Set conn=Nothing If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If %>
_____________________________
William Lee
|
|
|
|
reem_04
Posts: 13 Joined: 10/29/2007 Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 6:16:58
hi again thanks alot (the code that you send to me before it work ,but it repated recod 7 times and all of the data in differet recored repated 7 times ) sorry i recivie this error but the ADODB.Command error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /inside/Dept_Safety_Inspection_Report/admin_prv_copy(1).asp, line 77 here is the code <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="../../Connections/intraweb.asp" --> <% ' *** 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.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString) End If ' boolean to abort record edit MM_abortEdit = false ' query string to execute MM_editQuery = "" %> <% ' *** Insert Record: set variables If (CStr(Request("MM_insert")) = "form1") Then MM_editTable = "dbo.dept_safety_Inspection_report_g" MM_editRedirectUrl = "new_conf.asp" MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value" MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',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_fields(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 %> <% ' *** Insert Record: construct a sql insert statement and execute it Dim MM_tableValues Dim MM_dbValues Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = conn '*** MM_editConnection If (CStr(Request("MM_insert")) <> "") Then ' create the sql insert statement MM_tableValues = "" MM_dbValues = "" Response.write MM_i ' **** to test value for MM_i before it goes into the For..Next Loop MM_i=0 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_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End If MM_tableValues = MM_tableValues & MM_columns(MM_i) MM_dbValues = MM_dbValues & MM_formVal MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")" Response.write MM_editQuery ' see what the SQL statement is like If (Not MM_abortEdit) Then ' execute the insert Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = MM_editConnection MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute End if next conn.Close Set conn=Nothing If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If %> <!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> <link href="stylesindex.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="1024" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td background="../images/Radiology2_02.jpg"><form action="<%=MM_editAction%>" method="post" name="form1" id="form1"> <table align="center" width="879"> <tr valign="baseline"> <td align="center" nowrap="nowrap" class="style2" width="50"><b>Item no.</b></td> <td class="style3" width="309" align="center"><b>Item</b></td> <td align="center" width="50"> <p align="center"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Yes- No -N/A</font></span></td> <td align="center" width="173"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Corrective Action</font></span></td> <td align="center" width="134"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Responsibility</font></span></td> <td align="center" width="103"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Target Date</font></span></td> <td align="center" width="88"> <span style="font-weight: 700"> <font face="Verdana" style="font-size: 8pt">Date Completed</font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.1"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q1</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.2"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q2</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.3"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q3</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.4"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q4</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr valign="baseline"> <td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"> </td> </tr> <tr valign="baseline"> <td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"><div align="left"></div> <p align="center"><input type="submit" value="Insert record"/> </td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> </td> </tr> </table> <% set conn=Server.CreateObject("ADODB.Connection") conn.ConnectionString=MM_intraweb_String conn.Open %> </body> </html>
|
|
|
|
reem_04
Posts: 13 Joined: 10/29/2007 Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 7:04:13
hi again this is the error i recivie 14insert into dbo.dept_safety_Inspection_report_g (Item) values ('q1, q2, q3, q4') ADODB.Command error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /inside/Dept_Safety_Inspection_Report/admin_prv_copy(1).asp, line 122 this is the code <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="../../Connections/intraweb_new.asp" --> <% ' *** 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.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString) End If ' boolean to abort record edit MM_abortEdit = false ' query string to execute MM_editQuery = "" %> <% ' *** Insert Record: set variables If (CStr(Request("MM_insert")) = "form1") Then MM_editTable = "dbo.dept_safety_Inspection_report_g" MM_editRedirectUrl = "new_conf.asp" MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value" MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',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_fields(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 %> <% ' *** Insert Record: construct a sql insert statement and execute it Dim MM_tableValues Dim MM_dbValues Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = conn '*** MM_editConnection If (CStr(Request("MM_insert")) <> "") Then ' create the sql insert statement MM_tableValues = "" MM_dbValues = "" Response.write MM_i ' **** to test value for MM_i before it goes into the For..Next Loop MM_i=0 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_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End If MM_tableValues = MM_tableValues & MM_columns(MM_i) MM_dbValues = MM_dbValues & MM_formVal MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")" Response.write MM_editQuery ' see what the SQL statement is like If (Not MM_abortEdit) Then ' execute the insert Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = MM_editConnection MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute End if next conn.Close Set conn=Nothing If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If %> <!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> <link href="stylesindex.css" rel="stylesheet" type="text/css" /> </head> <body> <table width="1024" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td background="../images/Radiology2_02.jpg"><form action="<%=MM_editAction%>" method="post" name="form1" id="form1"> <table align="center" width="879"> <tr valign="baseline"> <td align="center" nowrap="nowrap" class="style2" width="50"><b>Item no.</b></td> <td class="style3" width="309" align="center"><b>Item</b></td> <td align="center" width="50"> <p align="center"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Yes- No -N/A</font></span></td> <td align="center" width="173"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Corrective Action</font></span></td> <td align="center" width="134"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Responsibility</font></span></td> <td align="center" width="103"> <span style="font-weight: 700"><font face="Verdana" style="font-size: 8pt"> Target Date</font></span></td> <td align="center" width="88"> <span style="font-weight: 700"> <font face="Verdana" style="font-size: 8pt">Date Completed</font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.1"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q1</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.2"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q2</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.3"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q3</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr> <td align="right" nowrap="nowrap" class="style2" width="50" height="75"> <p align="center"> <input type="text" name="Item_num" size="4" value="1.4"></td> <td class="style3" width="309" height="75"> <textarea rows="4" name="item" cols="36">q4</textarea></td> <td align="left" width="50"><font face="Verdana" style="font-size: 8pt"> <select size="3" name="G_Yes"> <option selected value="Yes">Yes</option> <option value="N/A">N/A</option> <option value="No">No</option> </select> </font> </td> <td align="left" width="173"><font face="Verdana" style="font-size: 8pt"> <textarea rows="4" name="Corrective_Action" cols="19"></textarea></font></td> <td align="left" width="134"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Responsibility" size="20"></font></td> <td align="left" width="103"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Target_Date" size="19"></font></td> <td align="left" width="88"><font face="Verdana" style="font-size: 8pt"> <input type="text" name="Date_Completed" size="16"></font></td> </tr> <tr valign="baseline"> <td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"> </td> </tr> <tr valign="baseline"> <td align="right" nowrap="nowrap" class="style2" width="873" colspan="7"><div align="left"></div> <p align="center"><input type="submit" value="Insert record"/> </td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> </td> </tr> </table> </body> </html>
|
|
|
|
William Lee
Posts: 1080 Joined: 1/25/2002 From: Singapore Status: offline
|
RE: ADDING MULITPLE RECORD in ONE FORM ASP - 10/31/2007 7:24:56
You should be using the code below. quote:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="../../Connections/intraweb.asp" --> <% ' *** 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.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString) End If ' boolean to abort record edit MM_abortEdit = false ' query string to execute MM_editQuery = "" %> <% ' *** Insert Record: set variables If (CStr(Request("MM_insert")) = "form1") Then ' *** MM_editConnection = MM_intraweb_STRING ---comment out this line MM_editTable = "dbo.dept_safety_Inspection_report_g" MM_editRedirectUrl = "new_conf.asp" MM_fieldsStr = "Item|value|G_Yes|value|Corrective_Action|value|Responsibility|value|Target_Date|value|Date_Completed|value|Item_num|value" MM_columnsStr = "Item|',none,''|G_Yes|',none,''|Corrective_Action|',none,''|Responsibility|',none,''|Target_Date|',none,''|Date_Completed|',none,''|Item_num|',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_fields(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 %> <% ' *** Insert Record: construct a sql insert statement and execute it Dim MM_tableValues Dim MM_dbValues Set MM_editCmd = Server.CreateObject("ADODB.Command") MM_editCmd.ActiveConnection = conn '*** MM_editConnection If (CStr(Request("MM_insert")) <> "") Then ' create the sql insert statement MM_tableValues = "" MM_dbValues = "" Response.write MM_i ' **** to test value for MM_i before it goes into the For..Next Loop MM_i=0 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_tableValues = MM_tableValues & "," MM_dbValues = MM_dbValues & "," End If MM_tableValues = MM_tableValues & MM_columns(MM_i) MM_dbValues = MM_dbValues & MM_formVal MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")" Response.write MM_editQuery ' see what the SQL statement is like If (Not MM_abortEdit) Then ' execute the insert MM_editCmd.CommandText = MM_editQuery MM_editCmd.Execute End if next conn.Close Set conn=Nothing If (MM_editRedirectUrl <> "") Then Response.Redirect(MM_editRedirectUrl) End If End If %>
_____________________________
William Lee
|
|
|
|
William Lee
Posts: 1080 Joined: 1/25/2002 From: Singapore
| |