acaraciolo
asked on
Not getting expected error!
hello all - Thanks for all the help from 'fritz the blank' and 'golfDoctor' I completed a web project that includes dynamic select boxes and use of ADO to enter and extract data to a web based microsoft access 7.0 database. Anyway I have one loose end involoving a unique filed. The database is defined as follows:
Fields:(Name - Type - Size)
-------------------------- ---------- --------
TxtNum Double 8
NetId Text 50
CktType Text 15
Network Text 15
Equip Text 30
Equip TypeText 30
Res Text 30
Other Memo 0
Date Date/Time 8
Time Date/Time 8
Indexes (Name - Fields - Unique)
-------------------------- ---------- ---------- ---
TxtNum +TxtNum True
The problem is I don't know how to identify an entry as unique, once the user hits submit. I assumed that if it tried to enter a duplicate entry it would generate an error, and I could trap the error for evaluation. Then do something like if err.number = x then alert user. Instead it acts normal as if everything was fine, except that if you go back and look at the batabase the entry isn't there. Here is the code that writes the data out:
<%
Dim txtNumber, txtNetID, txtCktType, txtNetwork, txtEquipList
Dim txtEquipType, txtEquipCode, txtOther, cDate, cTime
Dim conn, sql
cDate = Date
cTime = Time
txtNumber = Request.QueryString("txtNu mber")
txtNetID = Request.QueryString("txtNe tID")
txtCktType = Request.QueryString("txtCk tType")
txtNetwork = Request.QueryString("txtNe twork")
txtEquipList = Request.QueryString("txtEq uipList")
txtEquipType = Request.QueryString("txtEq uipType")
txtEquipCode = Request.QueryString("txtEq uipCode")
txtOther = Request.QueryString("txtOt her")
response.write("<p> < /p>")
response.write("<b><font face=""Arial"" size=""4"">")
response.write("Please wait while the page updates the<br>")
response.write("database.. ...")
response.write("<p> < /p>")
set conn=Server.CreateObject(" ADODB.Conn ection")
conn.Provider="Microsoft.J et.OLEDB.4 .0"
Conn.Mode = 3
conn.Open Server.MapPath("ProActive. mdb")
'set rs=Server.CreateObject("AD ODB.record set")
'rs.Open "Select * from tblMain", conn
sql = "INSERT INTO tblMain VALUES ('"
sql = sql & txtNumber & "','"
sql = sql & txtNetID & "','"
sql = sql & txtCktType & "','"
sql = sql & txtNetwork & "','"
sql = sql & txtEquipList & "','"
sql = sql & txtEquipType & "','"
sql = sql & txtEquipCode & "','"
sql = sql & txtOther & "','"
sql = sql & cDate & "','"
sql = sql & cTime & "')"
on error resume next
conn.Execute sql
if err<>0 then
response.write ("An Error has occured, of the type '" & Err.description & "' ,")
response.write ("<br> number: " & err.Number)
else
response.write ("Done.")
end if
conn.close
response.redirect("http://maoc.mcilink.com/pnmc.htm")
%>
Fields:(Name - Type - Size)
--------------------------
TxtNum Double 8
NetId Text 50
CktType Text 15
Network Text 15
Equip Text 30
Equip TypeText 30
Res Text 30
Other Memo 0
Date Date/Time 8
Time Date/Time 8
Indexes (Name - Fields - Unique)
--------------------------
TxtNum +TxtNum True
The problem is I don't know how to identify an entry as unique, once the user hits submit. I assumed that if it tried to enter a duplicate entry it would generate an error, and I could trap the error for evaluation. Then do something like if err.number = x then alert user. Instead it acts normal as if everything was fine, except that if you go back and look at the batabase the entry isn't there. Here is the code that writes the data out:
<%
Dim txtNumber, txtNetID, txtCktType, txtNetwork, txtEquipList
Dim txtEquipType, txtEquipCode, txtOther, cDate, cTime
Dim conn, sql
cDate = Date
cTime = Time
txtNumber = Request.QueryString("txtNu
txtNetID = Request.QueryString("txtNe
txtCktType = Request.QueryString("txtCk
txtNetwork = Request.QueryString("txtNe
txtEquipList = Request.QueryString("txtEq
txtEquipType = Request.QueryString("txtEq
txtEquipCode = Request.QueryString("txtEq
txtOther = Request.QueryString("txtOt
response.write("<p> <
response.write("<b><font face=""Arial"" size=""4"">")
response.write("Please wait while the page updates the<br>")
response.write("database..
response.write("<p> <
set conn=Server.CreateObject("
conn.Provider="Microsoft.J
Conn.Mode = 3
conn.Open Server.MapPath("ProActive.
'set rs=Server.CreateObject("AD
'rs.Open "Select * from tblMain", conn
sql = "INSERT INTO tblMain VALUES ('"
sql = sql & txtNumber & "','"
sql = sql & txtNetID & "','"
sql = sql & txtCktType & "','"
sql = sql & txtNetwork & "','"
sql = sql & txtEquipList & "','"
sql = sql & txtEquipType & "','"
sql = sql & txtEquipCode & "','"
sql = sql & txtOther & "','"
sql = sql & cDate & "','"
sql = sql & cTime & "')"
on error resume next
conn.Execute sql
if err<>0 then
response.write ("An Error has occured, of the type '" & Err.description & "' ,")
response.write ("<br> number: " & err.Number)
else
response.write ("Done.")
end if
conn.close
response.redirect("http://maoc.mcilink.com/pnmc.htm")
%>
Looks like you're always going to redirect. Do a response.end after writing out the error.
Also, it's good practice to set "on error goto 0" after your error check so further errors in the page aren't ignored. I suspect you're getting an error on the redirect because you already wrote to the response object.
ASKER
fritz.. I modifyed the code as follows:
<%
Dim txtNumber, txtNetID, txtCktType, txtNetwork, txtEquipList
Dim txtEquipType, txtEquipCode, txtOther, cDate, cTime
Dim conn, sql
cDate = Date
cTime = Time
txtNumber = Request.QueryString("txtNu mber")
txtNetID = Request.QueryString("txtNe tID")
txtCktType = Request.QueryString("txtCk tType")
txtNetwork = Request.QueryString("txtNe twork")
txtEquipList = Request.QueryString("txtEq uipList")
txtEquipType = Request.QueryString("txtEq uipType")
txtEquipCode = Request.QueryString("txtEq uipCode")
txtOther = Request.QueryString("txtOt her")
response.write("<p> < /p>")
response.write("<b><font face=""Arial"" size=""4"">")
response.write("Please wait while the page updates the<br>")
response.write("database.. ...")
response.write("<p> < /p>")
set conn=Server.CreateObject(" ADODB.Conn ection")
conn.Provider="Microsoft.J et.OLEDB.4 .0"
Conn.Mode = 3
conn.Open Server.MapPath("ProActive. mdb")
set rs=Server.CreateObject("AD ODB.record set")
sql = "SELECT * FROM tblMain WHERE TxtNum = " & txtNumber
rs.Open sql, conn
if rs.EOF = True Then
rs.AddNew
rs.Fields("TxtNum") = txtNumber
rs.Fields("NetID") = txtNetID
rs.Fields("CktType") = txtCktType
rs.Fields("Network") = txtNetwork
rs.Fields("Equip") = txtEquipList
rs.Fields("EquipType") = txtEquipType
rs.Fields("Res") = txtEquipCode
rs.Fields("Other") = txtOther
rs.Fields("Date") = cDate
rs.Fields("Time") = cTime
rs.Update
rs.close
conn.close
'response.redirect("http://maoc.mcilink.com/test1.htm")
else
rs.close
conn.close
response.write("<p> < /p>")
response.write("It appears you tried to enter a duplicate Ticket number...")
end if
%>
and got the following error.....
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
<%
Dim txtNumber, txtNetID, txtCktType, txtNetwork, txtEquipList
Dim txtEquipType, txtEquipCode, txtOther, cDate, cTime
Dim conn, sql
cDate = Date
cTime = Time
txtNumber = Request.QueryString("txtNu
txtNetID = Request.QueryString("txtNe
txtCktType = Request.QueryString("txtCk
txtNetwork = Request.QueryString("txtNe
txtEquipList = Request.QueryString("txtEq
txtEquipType = Request.QueryString("txtEq
txtEquipCode = Request.QueryString("txtEq
txtOther = Request.QueryString("txtOt
response.write("<p> <
response.write("<b><font face=""Arial"" size=""4"">")
response.write("Please wait while the page updates the<br>")
response.write("database..
response.write("<p> <
set conn=Server.CreateObject("
conn.Provider="Microsoft.J
Conn.Mode = 3
conn.Open Server.MapPath("ProActive.
set rs=Server.CreateObject("AD
sql = "SELECT * FROM tblMain WHERE TxtNum = " & txtNumber
rs.Open sql, conn
if rs.EOF = True Then
rs.AddNew
rs.Fields("TxtNum") = txtNumber
rs.Fields("NetID") = txtNetID
rs.Fields("CktType") = txtCktType
rs.Fields("Network") = txtNetwork
rs.Fields("Equip") = txtEquipList
rs.Fields("EquipType") = txtEquipType
rs.Fields("Res") = txtEquipCode
rs.Fields("Other") = txtOther
rs.Fields("Date") = cDate
rs.Fields("Time") = cTime
rs.Update
rs.close
conn.close
'response.redirect("http://maoc.mcilink.com/test1.htm")
else
rs.close
conn.close
response.write("<p> <
response.write("It appears you tried to enter a duplicate Ticket number...")
end if
%>
and got the following error.....
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
ASKER
joeposter649 - The redirect works fine I put <% response.buffer = true %> on the TOP line above the <HTML> tag. Also, while I didn't go into detail.... in testing I rem'd out the redirect to see any errors and none occured in the original page, the one I mentioned above occurs after I went from the INSERT INTO method to the rs.AddNew.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Fritz... I guess it had to do with how I was opening the data base....
Glad to have helped,
FtB
FtB
set conn=Server.CreateObject("
conn.Provider="Microsoft.J
Conn.Mode = 3
conn.Open Server.MapPath("ProActive.
'set rs=Server.CreateObject("AD
'rs.Open "Select * from tblMain", conn
I would create a sql select here with the parameters passed from the form. If you have rs.eof, then you know that no record exists, so you can just use the rs.addnew() method to populate your database. If you don't have rs.eof, then you know that the record already exists, so you can warn the user. Does that makes sense? If so, and you want to pursue that option, please let me know if you need a hand to implement.
FtB