Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit the records

Status
Not open for further replies.

Mun

Programmer
Mar 5, 2003
46
0
0
US
Hi ,

I've an ASP page which is retrieving all the records from the database. I would like to provide an option to the users that they can edit any record and save the changes in to the database. How do I write dynamic update statement to update that particular record user choose to edit.
Any help is appreciated, thanks in advance.

 
Thanx pete,

That wouldn't help me.
 
This is what I used to accomplish what you are talking about; unless I misunderstand you.

<!--#include file=&quot;adovbs.inc&quot;-->


<%
Response.Buffer = True

'Dim objRS, objConn, objDB

Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
' objConn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;& server.MapPath(&quot;FAQ.mdb&quot;)

'objConn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=&quot; & objDB & &quot;&quot;
'Set objRS = Server.CreateObject(&quot;ADODB.RecordSet&quot;)

Set objRS = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open &quot;dsn=projects&quot;

If request.querystring(&quot;action&quot;) = &quot;&quot; Then

SQL = &quot;SELECT * FROM tblProjects&quot;
Set objRS = objConn.execute(SQL)
%>

<table cellspacing=&quot;2&quot; cellpadding=&quot;2&quot; border=&quot;1&quot; align=&quot;center&quot;>
<tr>
<td valign=&quot;top&quot; colspan=&quot;4&quot;><a href=&quot;GenAdmin.asp?action=add&quot;></a></td>
</tr>

<tr>
<td align=&quot;center&quot; nowrap><b>Project Name</b></td>
<td align=&quot;center&quot; nowrap><b>Project Type</b></td>
<td align=&quot;center&quot; nowrap><b>Description</b></td>
<td align=&quot;center&quot; colspan=&quot;2&quot; nowrap><b>Configure</b></td>
</tr>
<%
If Not objRS.EOF Then
Do While Not objRS.EOF
response.write(&quot;<tr valign=&quot;&quot;top&quot;&quot;>&quot;)
response.write(&quot;<td>&quot; & Left(objRS(&quot;projName&quot;),100) & &quot;...</td>&quot;)
response.write(&quot;<td>&quot; & Left(objRS(&quot;projType&quot;),100) & &quot;...</td>&quot;)
response.write(&quot;<td>&quot; & Left(objRS(&quot;Description&quot;),100) & &quot;</td>&quot;)
response.write(&quot;<td align=&quot;&quot;center&quot;&quot;><a href=&quot;&quot;GenAdmin.asp?action=edit&ID=&quot;& objRS(&quot;project_ID&quot;) &&quot;&quot;&quot;>Edit</a></td>&quot;)
response.write(&quot;<td align=&quot;&quot;center&quot;&quot;><a href=&quot;&quot;GenAdmin.asp?action=delete&ID=&quot;& objRS(&quot;project_ID&quot;) &&quot;&quot;&quot; onclick=&quot;&quot;return confirm('This Will Permanently Remove This Project From The Database, Do You Want To Continue?')&quot;&quot;>Delete</a></td></tr>&quot;)
objRS.MoveNext
Loop
Else
response.write(&quot;<tr><td colspan=&quot;&quot;4&quot;&quot;>Sorry, Currently There Are No Projects In The Database!</td></tr>&quot;)
End If
%>
</table>

<%
ElseIf request.querystring(&quot;action&quot;) = &quot;edit&quot; Then
SQL = &quot;SELECT * FROM tblProjects WHERE project_ID='&quot; & request.querystring(&quot;ID&quot;) & &quot;'&quot;
Set objRS = objConn.Execute(SQL)
%>

<table align=&quot;center&quot; width=&quot;300&quot; cellspacing=&quot;2&quot; cellpadding=&quot;2&quot; border=&quot;0&quot;>
<form action=&quot;GenAdmin.asp?action=editprocess&quot; method=&quot;post&quot;>
<tr>
<td><b>Project Name:</b></td>
<td align=&quot;right&quot;><textarea rows=&quot;4&quot; cols=&quot;35&quot; name=&quot;projName&quot;><%= objRS(&quot;projName&quot;) %></textarea></td>
</tr>
<tr>
<td><b>Project Type:</b></td>
<td align=&quot;right&quot;><textarea rows=&quot;4&quot; cols=&quot;35&quot; name=&quot;projType&quot;><%= objRS(&quot;projType&quot;) %></textarea></td>
</tr>
<tr>
<td><b>Description:</b></td>
<td align=&quot;right&quot;><textarea rows=&quot;4&quot; cols=&quot;35&quot; name=&quot;Description&quot;><%= objRS(&quot;Description&quot;) %></textarea></td>
</tr>
<tr>
<td colspan=&quot;2&quot; align=&quot;center&quot;><input type=&quot;submit&quot; value=&quot;Save&quot;>&nbsp;<input type=&quot;Reset&quot;></td>
</tr>
<input type=&quot;hidden&quot; name=&quot;project_ID&quot; value=&quot;<%= objRS(&quot;project_ID&quot;) %>&quot;>
</form>
</table>

<%
ElseIf request.querystring(&quot;action&quot;) = &quot;editprocess&quot; Then
If request.form(&quot;projName&quot;) = &quot;&quot; OR request.form(&quot;Description&quot;) = &quot;&quot; Then
response.clear
response.redirect(&quot;GenAdmin.asp?action=edit&ID=&quot; & request.form(&quot;project_ID&quot;) & &quot;&msg=2&quot;)
Else
SQL = &quot;UPDATE tblprojects SET projName = '&quot; & request.form(&quot;projName&quot;) & &quot;', projType = '&quot; & request.form(&quot;projType&quot;) & &quot;', Description = '&quot; & request.form(&quot;Description&quot;) & &quot;' WHERE project_ID = '&quot; & request.form(&quot;project_ID&quot;) & &quot;'&quot;
Set objRS = objConn.execute(SQL)
response.clear
response.redirect(&quot;GenAdmin.asp?msg=1&quot;)
End If
%>
<%
ElseIf request.querystring(&quot;action&quot;) = &quot;delete&quot; Then
SQL = &quot;DELETE FROM tblprojects WHERE project_ID ='&quot; & request.querystring(&quot;ID&quot;) & &quot;'&quot;
Set objRS = objConn.Execute(SQL)
response.clear
response.redirect(&quot;GenAdmin.asp?msg=1&quot;)
%>
Now that the delete function is out of the way we take a look at the add function. Once again we do this with the action querystring by setting it to add.
<%
ElseIf request.querystring(&quot;action&quot;) = &quot;add&quot; Then
%>
<table align=&quot;center&quot; width=&quot;300&quot; cellspacing=&quot;2&quot; cellpadding=&quot;2&quot; border=&quot;0&quot;>
<form action=&quot;GenAdmin.asp?action=addprocess&quot; method=&quot;post&quot;>

<tr>
<td><b>Project Name:</b></td>
<td align=&quot;right&quot;><textarea rows=&quot;4&quot; cols=&quot;25&quot; name=&quot;projName&quot;></textarea></td>
</tr>
<tr>
<td><b>Project Type:</b></td>
<td align=&quot;right&quot;><textarea rows=&quot;4&quot; cols=&quot;25&quot; name=&quot;projType&quot;></textarea></td>
</tr>

<tr>
<td><b>Description:</b></td>
<td align=&quot;right&quot;><textarea rows=&quot;4&quot; cols=&quot;25&quot; name=&quot;Description&quot;></textarea></td>
</tr>
<tr>
<td colspan=&quot;2&quot; align=&quot;center&quot;><input type=&quot;submit&quot; value=&quot;Save&quot;>&nbsp;<input type=&quot;Reset&quot;></td>
</tr>
</form>
</table>
<%
ElseIf request.querystring(&quot;action&quot;) = &quot;addprocess&quot; Then
If request.form(&quot;projName&quot;) = &quot;&quot; OR request.form(&quot;Description&quot;) = &quot;&quot; Then
response.clear
response.redirect(&quot;GenAdmin.asp?action=add&msg=2&quot;)
Else
SQL = &quot;INSERT INTO OFAQ (Question, Answer) Values('&quot; & request.form(&quot;projName&quot;) & &quot;', '&quot; & request.form(&quot;Description&quot;) & &quot;')&quot;
Set objRS = objConn.execute(SQL)
response.clear
response.redirect(&quot;GenAdmin.asp?msg=1&quot;)
End If
End If
%>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top