Variable is undefined 'adModeReadWrite'  | Familiar Sight | | Join Date: Dec 2007 Location: Patna
Posts: 198
| |
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. -
<%@ Language=VBScript%>
-
<%Option Explicit%>
-
<html>
-
<head>
-
<title>Barauni Refinery - Post Retirement Data Management</title>
-
</head>
-
<body>
-
<%
-
Dim R
-
Dim R1
-
Dim vcategory, vgrade, vamount
-
Dim errorMsg
-
Dim conn
-
Dim i
-
Set conn = Server.Createobject("ADODB.Connection")
-
conn.Open "DSN=ORA; User ID = scott; Password = tiger"
-
Set R = Server.CreateObject("ADODB.Recordset")
-
Set R1 = Server.CreateObject("ADODB.Recordset")
-
If Not IsEmpty(Request.Form("submit")) then
-
vcategory = Request.Form("vcategory")
-
vgrade = Request.Form("vgrade")
-
vamount = Request.Form("amount")
-
If len(vcategory) = 0 then
-
errorMsg = "You must enter category."
-
End If
-
If len(errorMsg) = 0 Then
-
If len(vgrade) = 0 Then
-
errorMsg = "Your must enter grade."
-
Elseif len(vgrade) > 10 Then
-
errorMsg = "The employee grade > 10 characters. Please reduce the size."
-
Else
-
For i = 1 to len(vgrade)
-
If instr(1, "_/()[]{}abcdefghijklmnopqrstuvwxyz0123456789 ", mid(vgrade, i, 1), vbTextCompare) = 0 then
-
errorMsg = "The employee grade you entered is invalid. Please re-enter this field."
-
Exit For
-
End If
-
Next
-
End If
-
End If
-
If len(errorMsg) = 0 Then
-
conn.Close
-
conn.Mode = adModeReadWrite
-
conn.Open
-
R.Open "Select * from grademst", conn, adOpenStatic, adLockOptimistic, adCmdText
-
R.Addnew
-
R("category") = vcategory
-
R("grade") = vgrade
-
R("amount") = vamount
-
R.UPdate
-
R.Close
-
End If
-
End If
-
%>
-
<div style="Position:Absolute; top:120; left:50; background-color: #f0f0f0">
-
<h2>SABF Entry</h3>
-
<hr>
-
<p>
-
<form method="POST" action="grade.asp">
-
<%
-
If len(errorMsg) > 0 Then
-
Response.Write "<p><font color='red'>" & errorMsg & "</font></p>"
-
End If
-
%>
-
<table width=900>
-
<tr>
-
<table align="center">
-
<tr>
-
<td align="center"><font face="arial"><h3>Employee Grading Master</h3></font></h3>
-
</tr>
-
</table>
-
</tr>
-
<tr>
-
<table align="center">
-
<tr>
-
<td align="right"><font face="arial" size=2>Grade : </font></td>
-
<td align='left'>
-
<select name="vgrade">
-
<option value="I" selected>I</option>
-
<option value="II">II</option>
-
<option value="III">III</option>
-
<option value="IV">IV</option>
-
</select>
-
</td>
-
</tr>
-
-
<tr>
-
<td align="right"><font face="arial" size=2>Category : </font></td>
-
<td align='left'>
-
<select name="vcategory">
-
<option value="Officer">Officer</option>
-
<option value="staff" selected>Staff</option></select>
-
</select>
-
</td>
-
</tr>
-
-
<tr>
-
<td align="right"><font face="arial" size=2>Amount : </font></td>
-
<td align='left'><input type="text" style="width:100px" name="vamount"></td>
-
</tr>
-
-
</table>
-
<tr>
-
<table align="center">
-
<tr>
-
<td align="center"><input type="Submit" name="submit" value="Save">
-
<input type="reset" name="reset" value="Reset">
-
</td>
-
</tr>
-
</table>
-
</tr>
-
</table>
-
</form>
-
</p>
-
</div>
-
-
</body>
-
</html>
-
| |
best answer - posted 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 -
<html>
-
<head>
-
<title>FormPage.asp</title>
-
</head>
-
<body>
-
<p>
-
<%
-
Select Case Request("Error")
-
Case "0"
-
Response.Write("Update done.")
-
Case "1"
-
Response.Write("No update was done.")
-
End Select
-
%>
-
</p>
-
<form name="xForm" method="post" action="PostPage.asp">
-
Amount: <input type="text" name="vamount">
-
<br />
-
<input type="Submit" name="submit" value="Save">
-
</form>
-
</body>
-
</html>
-
PostPage.asp -
<%
-
Response.CacheControl = "no-cache"
-
Response.AddHeader "Pragma", "no-cache"
-
Response.Expires = -1
-
-
Set Conn = Server.CreateObject("ADODB.Connection")
-
Conn.Open("DSN=dsn_ois;UID=scott;PWD=tiger;"))
-
-
On Error Resume Next
-
SQL = "INSERT INTO grademst (category, grade, amount) VALUES('Officer', 'II', '1')"
-
Conn.Execute SQL
-
-
If Err <> 0 Then
-
Response.Redirect("FormPage.asp?Error=1")
-
Else
-
Response.Redirect("FormPage.asp?Error=0")
-
End If
-
%>
-
Hope this helps,
CroCrew~
|  | Expert | | Join Date: Jan 2008 Location: Michigan
Posts: 338
| | | re: Variable is undefined 'adModeReadWrite'
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~
|  | Expert | | Join Date: Jan 2008 Location: Michigan
Posts: 338
| | | re: Variable is undefined 'adModeReadWrite'
Hello vikas251074,
Ok, let try to make this simple. Try this:
Hope this helps,
CroCrew~
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | re: Variable is undefined 'adModeReadWrite'
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
|  | Familiar Sight | | Join Date: Dec 2007 Location: Patna
Posts: 198
| | | re: Variable is undefined 'adModeReadWrite'
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
|  | Familiar Sight | | Join Date: Dec 2007 Location: Patna
Posts: 198
| | | re: Variable is undefined 'adModeReadWrite'
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.
|  | Expert | | Join Date: Jan 2008 Location: Michigan
Posts: 338
| | | re: Variable is undefined 'adModeReadWrite'
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: -
Set Conn = Server.CreateObject("ADODB.Connection")
-
Conn.Open("DSN=dsn_ois;UID=scott;PWD=tiger;")
-
-
Set rs = Server.CreateObject("ADODB.Recordset")
-
SQL = "SELECT category, grade, amount FROM grademst"
-
rs.Open SQL, Conn
-
-
Do Until (rs.EOF)
-
Response.Write("Category: " &rs("category").value & " ")
-
Response.Write("Grade: " &rs("grade").value & " ")
-
Response.Write("Amount: " &rs("amount").value)
-
Response.Write("<br /> <br />")
-
rs.MoveNext
-
Loop
-
Hope this helps,
CroCrew~
|  | Familiar Sight | | Join Date: Dec 2007 Location: Patna
Posts: 198
| | | re: Variable is undefined 'adModeReadWrite'
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 ? ..
|  | Expert | | Join Date: Jan 2008 Location: Michigan
Posts: 338
| | | re: Variable is undefined 'adModeReadWrite'
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 -
<html>
-
<head>
-
<title>FormPage.asp</title>
-
</head>
-
<body>
-
<p>
-
<%
-
Select Case Request("Error")
-
Case "0"
-
Response.Write("Update done.")
-
Case "1"
-
Response.Write("No update was done.")
-
End Select
-
%>
-
</p>
-
<form name="xForm" method="post" action="PostPage.asp">
-
Amount: <input type="text" name="vamount">
-
<br />
-
<input type="Submit" name="submit" value="Save">
-
</form>
-
</body>
-
</html>
-
PostPage.asp -
<%
-
Response.CacheControl = "no-cache"
-
Response.AddHeader "Pragma", "no-cache"
-
Response.Expires = -1
-
-
Set Conn = Server.CreateObject("ADODB.Connection")
-
Conn.Open("DSN=dsn_ois;UID=scott;PWD=tiger;"))
-
-
On Error Resume Next
-
SQL = "INSERT INTO grademst (category, grade, amount) VALUES('Officer', 'II', '1')"
-
Conn.Execute SQL
-
-
If Err <> 0 Then
-
Response.Redirect("FormPage.asp?Error=1")
-
Else
-
Response.Redirect("FormPage.asp?Error=0")
-
End If
-
%>
-
Hope this helps,
CroCrew~
|  | Similar ASP / Active Server Pages bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,392 network members.
|