<% ' 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"

<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">

<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
<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>
<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>
<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> -
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
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.
<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>
<b><font size="4">Here is your wizard-generated asp database display script.
<b>'save as <%=request.form("Table")%>_editrecord.asp</b><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>
end if<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>
dim strKey<br>
strKey = request.form(&quot;key&quot;)<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>
&lt;%Set rs = conn.Execute(&quot;SELECT * FROM <%=request.form("Table")%> WHERE
[<%=request.form("key")%>]=&quot;&amp; strKey &amp; &quot;&quot;)%&gt; <br>
'save as editrecord<br>
If request.form(&quot;edit&quot;)=&quot;edit&quot; then</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

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>"

response.write &quot;Updated!&quot;<br>
end if<br>
%&gt; </p>
&lt;FORM ACTION=&quot;&lt;%=request.servervariables(&quot;script_name&quot;)%&gt;?key=&lt;%=request.form(&quot;key&quot;)%&gt;&quot;
&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>

'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


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

Set rs = Nothing<br>
Set conn = Nothing<br>