How to use ASP & Oracle Add/Insert/Edit/Delete On Same Form This is tutorial asp developers ASP manage oracle table on Add/Insert/Update/Delete on same form.
ShotDev Focus:
- ASP & Oracle add/insert/update/delete on same form..
Example
asp_oracle_command.asp
<% Option Explicit %> <html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <% Dim Conn,strSQL,objRec,objExec,i Set Conn = Server.Createobject("ADODB.Connection") Conn.Open "Driver={Oracle in OraHome92};DBQ=TCDB;UID=myuser;PWD=mypassword;" '*** Add Condition ***' If Request.Form("hdnCmd") = "Add" Then strSQL = "" strSQL = strSQL &"INSERT INTO CUSTOMER " strSQL = strSQL &"(CUSTOMERID,NAME,EMAIL,COUNTRYCODE,BUDGET,USED) " strSQL = strSQL &"VALUES " strSQL = strSQL &"('"&Request.Form("txtAddCustomerID")&"','"&Request.Form("txtAddName")&"', '"&Request.Form("txtAddEmail")&"' " strSQL = strSQL &",'"&Request.Form("txtAddCountryCode")&"','"&Request.Form("txtAddBudget")&"', '"&Request.Form("txtAddUsed")&"') " Set objExec = Conn.Execute(strSQL) End IF '*** Update Condition ***' If Request.Form("hdnCmd") = "Update" Then strSQL = "UPDATE CUSTOMER SET " strSQL = strSQL&"CUSTOMERID = '"&Request.Form("txtEditCustomerID")&"' " strSQL = strSQL&",NAME = '"&Request.Form("txtEditName")&"' " strSQL = strSQL&",EMAIL = '"&Request.Form("txtEditEmail")&"' " strSQL = strSQL&",COUNTRYCODE = '"&Request.Form("txtEditCountryCode")&"' " strSQL = strSQL&",BUDGET = '"&Request.Form("txtEditBudget")&"' " strSQL = strSQL&",USED = '"&Request.Form("txtEditUsed")&"' " strSQL = strSQL&"WHERE CUSTOMERID = '"&Request.Form("hdnEditCustomerID")&"' " Set objExec = Conn.Execute(strSQL) End IF '*** Delete Condition ***' If Request.QueryString("Action") = "Del" Then strSQL = "DELETE FROM CUSTOMER " strSQL = strSQL&"WHERE CUSTOMERID = '"&Request.QueryString("CusID")&"' " Set objExec = Conn.Execute(strSQL) End IF strSQL = "SELECT * FROM CUSTOMER " Set objRec = Server.CreateObject("ADODB.Recordset") objRec.Open strSQL, Conn, 1,3 %> <form name="frmMain" method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>"> <input type="hidden" name="hdnCmd" value=""> <table width="600" border="1"> <tr> <th width="91"> <div align="center">CustomerID </div></th> <th width="98"> <div align="center">Name </div></th> <th width="198"> <div align="center">Email </div></th> <th width="97"> <div align="center">CountryCode </div></th> <th width="59"> <div align="center">Budget </div></th> <th width="71"> <div align="center">Used </div></th> <th width="30"> <div align="center">Edit </div></th> <th width="30"> <div align="center">Delete </div></th> </tr> <% While Not objRec.EOF %> <% IF objRec.Fields("CUSTOMERID").Value = Request.QueryString("CusID") and Request.QueryString("Action") = "Edit" Then %> <tr> <td><div align="center"> <input type="text" name="txtEditCustomerID" size="5" value="<%=objRec.Fields("CUSTOMERID").Value%>"> <input type="hidden" name="hdnEditCustomerID" size="5" value="<%=objRec.Fields("CUSTOMERID").Value%>"> </div></td> <td><input type="text" name="txtEditName" size="20" value="<%=objRec.Fields("NAME").Value%>"></td> <td><input type="text" name="txtEditEmail" size="20" value="<%=objRec.Fields("EMAIL").Value%>"></td> <td><div align="center"><input type="text" name="txtEditCountryCode" size="2" value="<%=objRec.Fields("COUNTRYCODE").Value%>"></div></td> <td align="right"><input type="text" name="txtEditBudget" size="5" value="<%=objRec.Fields("BUDGET").Value%>"></td> <td align="right"><input type="text" name="txtEditUsed" size="5" value="<%=objRec.Fields("USED").Value%>"></td> <td colspan="2" align="right"><div align="center"> <input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();"> <input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<%=Request.ServerVariables("SCRIPT_NAME")%>';"> </div></td> </tr> <% Else %> <tr> <td><div align="center"><%=objRec.Fields("CUSTOMERID").Value%></div></td> <td><%=objRec.Fields("NAME").Value%></td> <td><%=objRec.Fields("EMAIL").Value%></td> <td><div align="center"><%=objRec.Fields("COUNTRYCODE").Value%></div></td> <td align="right"><%=objRec.Fields("BUDGET").Value%></td> <td align="right"><%=objRec.Fields("USED").Value%></td> <td align="center"><a href="<%=Request.ServerVariables("SCRIPT_NAME")%>?Action=Edit&CusID=<%=objRec.Fields("CUSTOMERID").Value%>">Edit</a></td> <td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<%=Request.ServerVariables("SCRIPT_NAME")%>?Action=Del&CusID=<%=objRec.Fields("CUSTOMERID").Value%>';}">Delete</a></td> </tr> <% End IF %> <% objRec.MoveNext Wend %> <tr> <td><div align="center"><input type="text" name="txtAddCustomerID" size="5"></div></td> <td><input type="text" name="txtAddName" size="20"></td> <td><input type="text" name="txtAddEmail" size="20"></td> <td><div align="center"><input type="text" name="txtAddCountryCode" size="2"></div></td> <td align="right"><input type="text" name="txtAddBudget" size="5"></td> <td align="right"><input type="text" name="txtAddUsed" size="5"></td> <td colspan="2" align="right"><div align="center"> <input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();"> </div></td> </tr> </table> </form> <% objRec.Close() Conn.Close() Set objRec = Nothing Set Conn = Nothing %> </body> </html>
Create a asp file and save to path root-path/myasp/
Run
http://localhost/myasp/asp_oracle_command.asp
Screenshot