Solved

insert data with ASP to oracle using form

Posted on 2004-04-12
3
599 Views
Last Modified: 2011-10-03
HI ALL

ineed the code for insert data to oracle database by using ASP form and HTMl

i'm using this code for reading data from my database


<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
personal_ino
<%
        Set OraDatabase = Server.CreateObject("ADODB.Connection")
        OraDatabase.ConnectionString= "provider=MSDAORA.1;Data source=alm;user id=s019699;password=s019699;"
        OraDatabase.open
        Set osRecordSet = OraDatabase.Execute("SELECT FIRST_NAME from personal_info")
      

        while not osRecordSet.EOF
             response.write osRecordSet("FIRST_NAME") & "<br>"
             osRecordSet.moveNext
          wend

        
        osRecordSet.Close
        OraDatabase.Close
      %>
</body>

</html>


how can ifix this code or how can i write now code for insert data by form

thanx for helping

regards




0
Comment
Question by:moon_face
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
Here is an example on Insert data into database using ASP:

Test.asp:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script language="javascript">
      function validate(frm) {
            //Add your validation here..
            return true;
      }
</script>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="processinsert.asp" onsubmit="return validation(this)">
  <table border="0" width="98%">
    <tr>
      <td width="30%" height="19" valign="top"><b>Value 1:</b></td>
      <td width="70%" height="19">
        <input type="text" name="value1" size="50" maxlength="255">
      </td>
    </tr>
    <tr>
      <td width="30%" height="19" valign="top">&nbsp; </td>
      <td width="70%" height="19" align="center">
        <div align="left">
          <p>
            <input type="submit"
          value="Submit" name="B2">
            <input type="reset" value="Reset" name="B1">
        </div>
      </td>
    </tr>
  </table>
</form>
</body>
</html>

processinsert.asp:

<%
      Response.expires = 0
      response.expiresabsolute = Now() - 1
      response.addHeader "pragma","no-cache"
      response.addHeader "cache-control","private"
      Response.CacheControl = "no-cache"
%>
<%
      dbConnectUser = "username"
      dbConnectPwd = "password"
      sid = "sid"
      user =  ""
      set conn=server.CreateObject("adodb.connection")
      conn.open "Provider=MSDASQL;DRIVER={Microsoft ODBC for ORACLE};UID=" & dbConnectUser &";PWD=" & dbConnectPwd & ";Server=" & sid

%>
<%
      Set Rs=Server.CreateObject("ADODB.Recordset")
      
      value1= Replace(request("value1"),"'","''")
            
      SQLStr = "Insert into tblTest (" & _
                   "value1 ) values ( " & _
                   "'" & value1 & "' " & _
                   ")"
      conn.execute SQLStr
      
      Conn.close
      Set Rs=Nothing
      Set Conn=Nothing

               //Redirect to thank you page if necessary
             response.redirect "thnkyou.asp"
%>

For more info on Oracle ConnectionString, see:

http://www.connectionstrings.com
http://www.able-consulting.com/ADO_Conn.htm

then look for Oracle..

Hope this helps
0
 

Author Comment

by:moon_face
Comment Utility
thanx for ur aswer and i tried to work with it in my data base but ihave proplem with this lines

__________________________________


     value1= Replace(request("value1"),"'","''")
 
         
     SQLstr= "Insert into tblTest(value1)values("'"& value1 &"'")"
               
     conn.execute SQLStr
__________________________________

and idon't what the problem ,,, icreated tblTest table with value1 field

 create table tblTest
 (value1 varchar2(15) not null,
 constraint value1 primary key(value1));

and i modify the code according to my database as :

<%
     Response.expires = 0
     response.expiresabsolute = Now() - 1
     response.addHeader "pragma","no-cache"
     response.addHeader "cache-control","private"
     Response.CacheControl = "no-cache"
%>
<%
     Set OraDatabase = Server.CreateObject("ADODB.Connection")
       OraDatabase.ConnectionString= "provider=MSDAORA.1;Data source=alm;user

id=s019699;password=s019699;"
       OraDatabase.open

%>
<%

     
     Set Rs=Server.CreateObject("ADODB.Recordset")
     
     value1= Replace(request("value1"),"'","''")
 
         
     SQLstr= "Insert into tblTest(value1)values("'"& value1 &"'")"
               
     conn.execute SQLStr
     
     
     Conn.close
     Set Rs=Nothing
     Set Conn=Nothing


//Redirect to thank you page if necessary

             response.redirect "thnkyou.asp"
%>

unfortinatly igot this error

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'conn'
/processinsert.asp, line 24

thanx for ur cooperate



0
 

Author Comment

by:moon_face
Comment Utility
thanx it works with me

thanx for help
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now