468,544 Members | 1,779 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

Variable is undefined 'adModeReadWrite'

vikas251074
198 100+
I am using ASP with Oracle 9i

When I try to save data by clicking save button, it gives following error.

Variable is undefined 'adModeReadWrite'

where as adModeReadWrite is an keyword. The error may in the line 42

What should be the problem.

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript%>
  2. <%Option Explicit%>
  3. <html>
  4. <head>
  5. <title>Barauni Refinery - Post Retirement Data Management</title>
  6. </head>
  7. <body>
  8. <%
  9. Dim R
  10. Dim R1 
  11. Dim vcategory, vgrade, vamount
  12. Dim errorMsg
  13. Dim conn
  14. Dim i
  15. Set conn = Server.Createobject("ADODB.Connection")
  16. conn.Open "DSN=ORA; User ID = scott; Password = tiger"
  17. Set R = Server.CreateObject("ADODB.Recordset")
  18. Set R1 = Server.CreateObject("ADODB.Recordset")
  19.   If Not IsEmpty(Request.Form("submit")) then
  20.     vcategory = Request.Form("vcategory")
  21.     vgrade = Request.Form("vgrade")
  22.     vamount = Request.Form("amount")
  23.     If len(vcategory) = 0 then
  24.       errorMsg = "You must enter category."
  25.     End If
  26.     If len(errorMsg) = 0 Then
  27.       If len(vgrade) = 0 Then
  28.         errorMsg = "Your must enter grade."
  29.       Elseif len(vgrade) > 10 Then
  30.         errorMsg = "The employee grade > 10 characters. Please reduce the size."
  31.       Else
  32.         For i = 1 to len(vgrade)
  33.           If instr(1, "_/()[]{}abcdefghijklmnopqrstuvwxyz0123456789 ", mid(vgrade, i, 1), vbTextCompare) = 0 then
  34.             errorMsg = "The employee grade you entered is invalid. Please re-enter this field."
  35.             Exit For
  36.           End If
  37.         Next
  38.       End If
  39.     End If
  40.     If len(errorMsg) = 0 Then
  41.       conn.Close
  42.       conn.Mode = adModeReadWrite
  43.       conn.Open
  44.       R.Open "Select * from grademst", conn, adOpenStatic, adLockOptimistic, adCmdText
  45.       R.Addnew
  46.       R("category") = vcategory
  47.       R("grade") = vgrade
  48.       R("amount") = vamount
  49.       R.UPdate
  50.       R.Close
  51.     End If
  52.   End If
  53. %>
  54.   <div style="Position:Absolute; top:120; left:50; background-color: #f0f0f0">
  55.     <h2>SABF Entry</h3>
  56.     <hr>
  57.     <p>
  58.     <form method="POST" action="grade.asp">
  59. <%
  60.       If len(errorMsg) > 0 Then
  61.         Response.Write "<p><font color='red'>" & errorMsg & "</font></p>"
  62.       End If
  63. %>
  64.       <table width=900>
  65.         <tr>
  66.           <table align="center">
  67.             <tr>
  68.               <td align="center"><font face="arial"><h3>Employee Grading Master</h3></font></h3>
  69.             </tr>
  70.           </table>
  71.         </tr>
  72.         <tr>
  73.           <table align="center">
  74.             <tr>
  75.               <td align="right"><font face="arial" size=2>Grade : </font></td>
  76.               <td align='left'>
  77.                 <select name="vgrade">
  78.                        <option value="I" selected>I</option>
  79.                        <option value="II">II</option>
  80.                        <option value="III">III</option>
  81.                        <option value="IV">IV</option>
  82.                 </select>
  83.               </td>
  84.             </tr>
  85.  
  86.             <tr>
  87.               <td align="right"><font face="arial" size=2>Category : </font></td>
  88.               <td align='left'>
  89.                 <select name="vcategory">
  90.                        <option value="Officer">Officer</option>
  91.                        <option value="staff" selected>Staff</option></select>
  92.                 </select>
  93.               </td>
  94.             </tr>
  95.  
  96.             <tr>
  97.               <td align="right"><font face="arial" size=2>Amount : </font></td>
  98.               <td align='left'><input type="text" style="width:100px" name="vamount"></td>
  99.             </tr>
  100.  
  101.           </table> 
  102.         <tr>
  103.           <table align="center">
  104.             <tr>
  105.               <td align="center"><input type="Submit" name="submit" value="Save">
  106.                                  <input type="reset" name="reset" value="Reset">
  107.               </td>
  108.             </tr>
  109.           </table>
  110.         </tr>
  111.       </table>
  112.     </form>
  113.     </p>
  114.   </div>
  115.  
  116. </body>
  117. </html>
  118.  
Oct 12 '09 #1

✓ answered by CroCrew

Hello vikas251074,

You are entering into a common problem in web development. When you hit the “refresh” button on a web browser; in all reality you are “re-doing” the page. So if you came to the page from a post then the post gets “refresh”ed too.

Just remember: the browser “refresh” button will repost anything that got posted to the page before.

There are a many workarounds that you can do to help you as a developer to stop double posts due to the browser “refresh” button. Here is one (uses two pages):

FormPage.asp
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>FormPage.asp</title>
  4.     </head>
  5.     <body>
  6.         <p>
  7.             <%
  8.                 Select Case Request("Error")
  9.                     Case "0"
  10.                         Response.Write("Update done.")
  11.                     Case "1"
  12.                         Response.Write("No update was done.")
  13.                 End Select
  14.             %>
  15.         </p>
  16.         <form name="xForm" method="post" action="PostPage.asp">
  17.             Amount: <input type="text" name="vamount">
  18.             <br />
  19.             <input type="Submit" name="submit" value="Save">
  20.         </form>
  21.     </body>
  22. </html>
  23.  
PostPage.asp
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Response.CacheControl = "no-cache"
  3.     Response.AddHeader "Pragma", "no-cache"
  4.     Response.Expires = -1
  5.  
  6.     Set Conn = Server.CreateObject("ADODB.Connection")  
  7.         Conn.Open("DSN=dsn_ois;UID=scott;PWD=tiger;")) 
  8.  
  9.         On Error Resume Next 
  10.             SQL = "INSERT INTO grademst (category, grade, amount) VALUES('Officer', 'II', '1')" 
  11.             Conn.Execute SQL 
  12.  
  13.             If Err <> 0 Then 
  14.                 Response.Redirect("FormPage.asp?Error=1")
  15.             Else
  16.                 Response.Redirect("FormPage.asp?Error=0")
  17.             End If
  18. %>
  19.  
Hope this helps,
CroCrew~

8 4317
CroCrew
564 Expert 512MB
Hello vikas251074,

I am looking at you VB code now and will try to post an answer to your question soon. For now I did look at the HTML part of your code and your <tags> are in bad need of help. You have nested <tags> where they should not be. Bad HTML could change the resulting display in ways that you might not want and could lead into thinking other parts of your code could be the culprit.

CroCrew~
Oct 12 '09 #2
CroCrew
564 Expert 512MB
Hello vikas251074,

Ok, let try to make this simple. Try this:

Expand|Select|Wrap|Line Numbers
  1. <% 
  2.     If Not IsEmpty(Request.Form("submit")) then 
  3.         vcategory = Request.Form("vcategory") 
  4.         vgrade = Request.Form("vgrade") 
  5.         vamount = Request.Form("amount") 
  6.         If len(vcategory) = 0 then 
  7.             errorMsg = "You must enter category." 
  8.         End If 
  9.         If len(errorMsg) = 0 Then 
  10.             If len(vgrade) = 0 Then 
  11.                 errorMsg = "Your must enter grade." 
  12.             Elseif len(vgrade) > 10 Then 
  13.                 errorMsg = "The employee grade > 10 characters. Please reduce the size." 
  14.             Else 
  15.                 For i = 1 to len(vgrade) 
  16.                     If instr(1, "_/()[]{}abcdefghijklmnopqrstuvwxyz0123456789 ", mid(vgrade, i, 1), vbTextCompare) = 0 then 
  17.                         errorMsg = "The employee grade you entered is invalid. Please re-enter this field." 
  18.                         Exit For 
  19.                     End If 
  20.                 Next 
  21.             End If 
  22.         End If 
  23.         If len(errorMsg) = 0 Then 
  24.             Set Conn = Server.CreateObject("ADODB.Connection") 
  25.                 Conn.Open("DSN=dsn_ois;UID=scott;PWD=tiger;"))
  26.  
  27.                 SQL = "INSERT INTO grademst (category, grade, amount) VALUES('" & vcategory & "', '" & vgrade & "', '" & vamount & "')"
  28.                 Conn.Execute SQL
  29.         End If 
  30.     End If 
  31. %> 
  32.  
  33. <html> 
  34.     <head> 
  35.         <title></title> 
  36.     </head> 
  37.     <body> 
  38.         <div style="Position:Absolute; top:120; left:50; background-color: #f0f0f0"> 
  39.             <h2>SABF Entry</h3> 
  40.             <hr> 
  41.             <p> 
  42.                 <form method="POST" action="grade.asp"> 
  43.                     <% 
  44.                         If len(errorMsg) > 0 Then 
  45.                             Response.Write "<p><font color='red'>" & errorMsg & "</font></p>" 
  46.                         End If 
  47.                     %> 
  48.                     <table width=900> 
  49.                         <tr> 
  50.                             <td>
  51.                                 <table align="center"> 
  52.                                     <tr> 
  53.                                         <td align="center"><font face="arial"><h3>Employee Grading Master</h3></font></h3> 
  54.                                     </tr> 
  55.                                 </table> 
  56.                             </td>
  57.                         </tr> 
  58.                         <tr> 
  59.                             <td>
  60.                                 <table align="center"> 
  61.                                     <tr> 
  62.                                         <td align="right"><font face="arial" size=2>Grade : </font></td> 
  63.                                         <td align='left'> 
  64.                                             <select name="vgrade"> 
  65.                                                 <option value="I" selected>I</option> 
  66.                                                 <option value="II">II</option> 
  67.                                                 <option value="III">III</option> 
  68.                                                 <option value="IV">IV</option> 
  69.                                             </select> 
  70.                                         </td> 
  71.                                     </tr> 
  72.                                     <tr> 
  73.                                         <td align="right"><font face="arial" size=2>Category : </font></td> 
  74.                                         <td align='left'> 
  75.                                             <select name="vcategory"> 
  76.                                                 <option value="Officer">Officer</option> 
  77.                                                 <option value="staff" selected>Staff</option></select> 
  78.                                             </select> 
  79.                                         </td> 
  80.                                     </tr> 
  81.                                     <tr> 
  82.                                         <td align="right"><font face="arial" size=2>Amount : </font></td> 
  83.                                         <td align='left'><input type="text" style="width:100px" name="vamount"></td> 
  84.                                     </tr> 
  85.                                 </table>  
  86.                             </td>
  87.                         </tr> 
  88.                         <tr> 
  89.                             <td>
  90.                                 <table align="center"> 
  91.                                     <tr> 
  92.                                         <td align="center">
  93.                                             <input type="Submit" name="submit" value="Save"> 
  94.                                             <input type="reset" name="reset" value="Reset"> 
  95.                                         </td> 
  96.                                     </tr> 
  97.                                 </table>
  98.                             </td>
  99.                         </tr> 
  100.                     </table> 
  101.                 </form> 
  102.             </p> 
  103.         </div> 
  104.     </body> 
  105. </html> 
  106.  

Hope this helps,
CroCrew~
Oct 12 '09 #3
jhardman
3,405 Expert 2GB
adModeReadWrite, for your future reference, is a constant, it should be set to some integer, probably between 0 and 5. Most tutorials that say to use that, also say to include a text file (via server-side include) named "adodb.inc" that includes a huge list of constants. You should also be able to google it to find the correct value.

Jared
Oct 12 '09 #4
vikas251074
198 100+
Thankyou sir

It indeed helps me a lot.

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("DSN=dsn_ois;UID=scott;PWD=tiger;"))

SQL = "INSERT INTO grademst (category, grade, amount) VALUES('" & vcategory & "', '" & vgrade & "', '" & vamount & "')"
Conn.Execute SQL

To display the the data from oracle table
I need to use recordset

I am using the following way

Set R = Server.CreateObject("ADODB.Recordset")
Set R = conn.Open SQL


This is not a correct syntax for opening recordset, it is giving error
Oct 13 '09 #5
vikas251074
198 100+
After googling a lot, I find the following suggestion

R = conn.execute (SQL)

but it is wrong. Then i use

R = conn.open (SQL)

still it is wrong. then what should i use there.
Oct 13 '09 #6
CroCrew
564 Expert 512MB
Hello vikas251074,

The query that you’re using does not return data from the database. A “SELECT” query would return data. Below is an example to return data:

Expand|Select|Wrap|Line Numbers
  1. Set Conn = Server.CreateObject("ADODB.Connection") 
  2. Conn.Open("DSN=dsn_ois;UID=scott;PWD=tiger;") 
  3.  
  4. Set rs = Server.CreateObject("ADODB.Recordset")
  5.     SQL = "SELECT category, grade, amount FROM grademst"
  6.     rs.Open SQL, Conn
  7.  
  8.     Do Until (rs.EOF)
  9.         Response.Write("Category: " &rs("category").value & " ")
  10.         Response.Write("Grade: " &rs("grade").value & " ")
  11.         Response.Write("Amount: " &rs("amount").value)
  12.         Response.Write("<br />&nbsp;<br />")
  13.         rs.MoveNext
  14.     Loop
  15.  
Hope this helps,
CroCrew~
Oct 13 '09 #7
vikas251074
198 100+
When I enter one record and click on save button, then it is saved

then when I just refreshed the page then again the same data is saved

This is quite alarming situation.

This can be controlled by following ways -

1) I should kill the value just after saving record

2) Restrick the duplicate entry of data.

I think first one may be very successful and logical.

What should I do and how ? ..
Oct 13 '09 #8
CroCrew
564 Expert 512MB
Hello vikas251074,

You are entering into a common problem in web development. When you hit the “refresh” button on a web browser; in all reality you are “re-doing” the page. So if you came to the page from a post then the post gets “refresh”ed too.

Just remember: the browser “refresh” button will repost anything that got posted to the page before.

There are a many workarounds that you can do to help you as a developer to stop double posts due to the browser “refresh” button. Here is one (uses two pages):

FormPage.asp
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>FormPage.asp</title>
  4.     </head>
  5.     <body>
  6.         <p>
  7.             <%
  8.                 Select Case Request("Error")
  9.                     Case "0"
  10.                         Response.Write("Update done.")
  11.                     Case "1"
  12.                         Response.Write("No update was done.")
  13.                 End Select
  14.             %>
  15.         </p>
  16.         <form name="xForm" method="post" action="PostPage.asp">
  17.             Amount: <input type="text" name="vamount">
  18.             <br />
  19.             <input type="Submit" name="submit" value="Save">
  20.         </form>
  21.     </body>
  22. </html>
  23.  
PostPage.asp
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Response.CacheControl = "no-cache"
  3.     Response.AddHeader "Pragma", "no-cache"
  4.     Response.Expires = -1
  5.  
  6.     Set Conn = Server.CreateObject("ADODB.Connection")  
  7.         Conn.Open("DSN=dsn_ois;UID=scott;PWD=tiger;")) 
  8.  
  9.         On Error Resume Next 
  10.             SQL = "INSERT INTO grademst (category, grade, amount) VALUES('Officer', 'II', '1')" 
  11.             Conn.Execute SQL 
  12.  
  13.             If Err <> 0 Then 
  14.                 Response.Redirect("FormPage.asp?Error=1")
  15.             Else
  16.                 Response.Redirect("FormPage.asp?Error=0")
  17.             End If
  18. %>
  19.  
Hope this helps,
CroCrew~
Oct 13 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by os2 | last post: by
10 posts views Thread by Sharon | last post: by
4 posts views Thread by Chris Beall | last post: by
148 posts views Thread by onkar | last post: by
pbmods
1 post views Thread by pbmods | last post: by
2 posts views Thread by Bob Bruyn | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.