Tuesday, May 1, 2012

Deleting and updating records using ASP

                         Deleting and updating records using ASP 

Here is a simple asp code for updating or deleting records from a MS Access database.


for del.asp:
<%
Dim f,l,c,e,co,sql,Rs
f= Request.Form("fn")
Dim objConn
set objConn=Server.CreateObject("ADODB.Connection")
objConn.Connectionstring="PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\wwwroot\ip\feedback.mdb"
Set Rs = Server.CreateObject("ADODB.Recordset")
objConn.Open
sql= "Delete * from [sugest] where fname='"&f&"'"
set Rs=objConn.Execute(sql)
objConn.close()
set objConn=nothing
Response.write("Deleted successfully!")
%>

for update.asp:

<%
Dim f,l,c,e,co,sql,Rs
f= Request.Form("fn")
Dim objConn
set objConn=Server.CreateObject("ADODB.Connection")
objConn.Connectionstring="PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Inetpub\wwwroot\ip\feedback.mdb"
Set Rs = Server.CreateObject("ADODB.Recordset")
objConn.Open
sql= "Update [sugest] set fname='shona' where fname='"&f&"'"
set Rs=objConn.Execute(sql)
objConn.close()
set objConn=nothing
%>
Dont forget to create a form to accept the name to be updated or deleted from records.for eg:
 form.asp:
<html>
<head>
</head>
<body>
<form method=post action="update.asp">
<input type=text name="fn">
<input type=submit value=Update  >
</form>
</body>
</html>
similarly prepare a form for del.asp.

No comments:

Post a Comment