<% ' save as editarecord.asp %>

<%
Response.expires = 0
Response.expiresabsolute = Now() - 1
Response.addHeader "pragma", "no-cache"
Response.addHeader "cache-control", "private"
Response.CacheControl = "no-cache"
%>
<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Create database record update edit script</title>
<link rel="stylesheet" type="text/css" href="../index.css">
</head>

<body>
<b><font face="Webdings" color="#FF0000">3</font></b><i><font size="1"><a href="http://www.classicaspreference.com/aspexamples/menu.htm">Back
to ASP Examples
Menu</a></font><br>
</i>
<b><font face="Webdings" color="#FF0000">3</font><font size="1"><i><a target="_blank" href="select_database.asp">Back
to Database Selection</a></i></font></b><br>
<b><font face="Webdings" color="#FF0000">3</font></b><i><font size="1"><a href="default.asp">Back to Database Interface Wizard Home Page</a></font><br>
</i>
<b><font face="Webdings" color="#FF0000">4</font><i><font size="1"><a title="Please let me know if this has been helpful." href="mailto:lilpeck@gmail.com?subject=database interface generation wizard">This
script cobbled together by Lil Peck</a></font></i></b><i><br>
</i>
<b><font face="Webdings" color="#FF0000">3</font></b><i><a href="javascript:history.go(-1)" onMouseOver="self.status=document.referrer;return true"><font color="#FF0000"><span style="text-decoration: none; font-weight: 700">Back</span></font></a><p>
<a target="_blank" href="http://www.4guysfromrolla.com/webtech/tips/t062801-1.shtml">Displaying All of the Form Variables</a> -
www.4guysfromrolla.com<br>
Use of <a target="_blank" href="http://www.w3schools.com/tags/ref_ascii.asp">ASCII characters</a>
to replace reserved ASP characters<br>
<a target="_blank" href="http://www.asp101.com/samples/viewasp.asp?file=db_simple.asp">
Simple database connection &amp; display</a> from ASP 101
</p>
<p>
I'm going to write versions to create scripts for database insertions and edits
also. Been up all night doing this one though, time to get some rest. If you
find this database interface generator wizard to be useful, please rate it or
send me an email.
</i></p>
<p>
<a href="http://www.classicaspreference.com/aspexamples/database_interface/testdisplay.asp">
Example of generated script in use.</a>&nbsp;
<font face="Webdings" color="#FF0000">
<b>4</b></font><b><a href="http://classicaspreference.com/aspexamples/counter/download.asp?file=dbinterfacewizard.zip">Download this script set</a><font face="Webdings" color="#FF0000">3</font><font face="Verdana" color="#FF0000">NOTE:
Script set will be updated this week.<br>
Be sure to edit the update sql statement to remove the first comma.</font><font size="4"><br>
&nbsp;</font></b></p>
<p>
<b><font size="4">Here is your wizard-generated asp database display script.
</font></b><i><br>
&nbsp;</font></b></p>
<p>&lt;%<br>
<b>'save as <%=request.form("Table")%>_editrecord.asp</b><br>
<br>
if request.form(&quot;key&quot;)=&quot;&quot; then&nbsp; 'the key is your
table field's primary key<br>
response.write &quot;Missing ID Number of Record to Edit!&quot; <br>
response.end<br>
end if<br>
%&gt;<br>
&nbsp;</p>
<p>&lt;%<br>
'Our ADO constants we'll need<br>
Const adOpenForwardOnly = 0<br>
Const adLockOptimistic = 3<br>
Const adCmdTable = &amp;H0002<br>
Dim conn ' ADO connection<br>
Dim rs ' ADO recordset<br>
Dim strDBPath ' path to our Access database (*.mdb) file<br>
<br>
dim strKey<br>
strKey = request.form(&quot;key&quot;)<br>
<br>
strDBPath = Server.MapPath(&quot;<%=request.form("dbname")%>&quot;)<br>
Set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)<br>
conn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; &amp; strDBPath &amp; &quot;;&quot;<br>
<br>
%&gt;<br>
&lt;%Set rs = conn.Execute(&quot;SELECT * FROM <%=request.form("Table")%> WHERE
[<%=request.form("key")%>]=&quot;&amp; strKey &amp; &quot;&quot;)%&gt; <br>
<br>
<br>
&lt;%<br>
'save as editrecord<br>
If request.form(&quot;edit&quot;)=&quot;edit&quot; then</p>
<p>

<i>
<p>
<%

'Display the Request.Form collection
For Each item In Request.Form

dim strHowmany, strCol

strHowmany = Len(item)-1
strCol = Right(item,(strHowmany))
if NOT item = "Table" then
if NOT item = "dbname" then
if NOT item = "key" then

strPrint = strPrint + ", " + strCol &"&#061;&#039;&#034; & request.form(&quot"&strCol&"&quot) &&#034;&#039;&#034; &&#034;"

'strPrint = strPrint + strCol &"&#061;&#039;&#034; & request.form(&quot"&strCol&"&quot) &&#034;&#039;&#034; &&#034;,&nbsp;"




end if
end if
end if





next
response.write "sql = &quot;UPDATE "& request.form("Table") &" SET "& strPrint & " WHERE "& request.form("key") &"=&quot; &amp; request.form(&quot;key&quot;) &amp; &quot;&quot; &#039; <font color=red>Edit this sql to remove the first comma</font>"


%><br>
<br>
conn.execute(sql)<br>
response.write &quot;Updated!&quot;<br>
end if<br>
%&gt; </p>
<p>
&lt;table&gt;&lt;tr&gt;<br>
&lt;FORM ACTION=&quot;&lt;%=request.servervariables(&quot;script_name&quot;)%&gt;?key=&lt;%=request.form(&quot;key&quot;)%&gt;&quot;
METHOD=POST&gt;<br>
&lt;INPUT TYPE=hidden NAME=&quot;edit&quot; value=&quot;edit&quot;&gt;<br>
&lt;INPUT TYPE=hidden NAME=&quot;key&quot; value=&quot;&lt;%=request.form(&quot;key&quot;)%&gt;&quot;&gt;</p>
<p><%

'Display the Request.Form collection
For Each sItem In Request.Form
dim strCnt, strFld,strTnm

strCnt = Len(sItem)-1
strFld = Right(sItem,(strCnt))
'If NOT Left( item, 1 ) = "T" Then
if NOT sItem = "Table" then
if NOT sItem = "dbname" then
if NOT sitem = "key" then
'response.write"&#60;td&#62;"&"&#60;&#37;&#61; " & "rs.Fields("& "&#34;" &strFld &"&#34;"&").Value &#37;&#062;&#60;&#47;td&#62;<br><br>"
response.write "&#60;td&#62;&#60;input type="&"&#34;text&#34;"&" name=&#34;"& strFld &"&#34; size="&"&#34;30&#34;"& " value=&#34;"& "&#60;&#37;&#61; " & "rs.Fields("& "&#34;" &strFld &"&#34;"&").Value &#37;&#062;" &"&#34;&#62;&#60;&#47;td&#62;<br><br>"
end if
end if
end if

Next


%></p>
<p>&nbsp;&lt;INPUT TYPE=SUBMIT&gt;</p>
<p>&lt;/FORM&gt;</p><br>

</i>
<p><i>&lt;/tr&gt;&lt;/table&gt;&lt;%<br>
rs.Close<br>
Set rs = Nothing<br>
conn.Close<br>
Set conn = Nothing<br>
<br>
%&gt;</i></p>
</body>

</html>