|
| |
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
delete record - 12/30/2004 12:43:40
Hey guys...I need help with getting this code to work.....Can anyone tell me whats wrong??? </head>
<body>
<!--#INCLUDE VIRTUAL="/includes/connection.asp" -->
<%
DIM mySQL, objRS
mySQL = "SELECT LastName FROM PatientRegistration"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn
%>
<p>Please enter the name that you would like to delete:</p>
<form name="DeleteRecord" method="Post" action="confirm.asp">
<table>
<tr><td>Name: </td>
<td><input type="text" name="LastName" value="Last Name" size="21"></td></tr>
</table>
<input type="submit" name="Submit" value="Submit">
</body>
</html><%
DIM strLastName
strState = Request.Form("LastName")
IF strLastName<> "" THEN
%>
<!--#INCLUDE VIRTUAL="/includes/connection.asp" -->
<%
DIM mySQL, objRS
mySQL = "SELECT * FROM PatientRegistration WHERE LastName = ' " & strLastName& " ' "
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mySQL, objConn, adOpenKeyset, adLockPessimistic, adCmdText
IF objRS.EOF THEN
Response.Write "Sorry, you are not inrolled in this class. Please click back on your browser and enter a different name."
ELSE
objRS.MoveFirst
objRS.Delete
objRS.Close
Set objRS = Nothing
Response.Write "" & strLastName & " has been succesffully deleted from your database."
END IF
objRS.Close
Set objRS = Nothing
objCONN.Close
Set objCONN = Nothing
%>
<%
ELSE
Response.Write "Please click back on your browser and select a name to delete."
END IF
%>
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 12:52:45
what is it doing? does it work? what happens when you run it? shouldnt this section be looping to find it? ELSE objRS.MoveFirst objRS.Delete objRS.Close Set objRS = Nothing
_____________________________
Dan
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 13:05:03
well right now when i run it all it does is print the "Response.Write "Please click back on your browser and select a name to delete." line.....if i put loop in there i get this Microsoft VBScript compilation error '800a040e' 'loop' without 'do' /confirm.asp, line 33 Loop
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 13:09:15
one step at a time. on your first page, what is the purpose of the recordset? it doesnt appear to me that you are writing the names into the form fror the user to chose one (which is one way of doing it). it appears to me that you have just provided an input text for them to key in a name which will be passed to the asp page, thus my question: what is the purpose of that asp code in page 1?
_____________________________
Dan
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 13:12:53
am i correct in assuming that people has signed up for a class and this is how they can resign(delete)? if they type in a name, you wont find it unless they type it in exactly the way it is in your database, right? if you bring all the names into a select structure and let them choose one, dont you run the risk of someone deviously deleting someone else? just thoughts
_____________________________
Dan
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 13:18:06
yeah all this was suppost to be was they type there name in and it takes them out of the class.....that was one of my concerns that they wouldn't type there name in right.....so how can i fix this so they can select there name....should i just start all over or can i use some stuff in this code....
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 13:32:48
the cleanest way to get the delete, in my limited experience, would be to read the names from th db into a select field in a form, then let them select one which is passed to anaother page which deletes. however, before you do that, think about my previous comment. is this a secure area? if not, any knuckhead in the world stumbling upon you page could depete all the records. however, if you have already assigned some sort of user code or password, then you can use that to test before processing the delete. in fact, if that is in the db, i suspect you could just have them enter that - then you would go to the db and get that name and post back to a form where they confirm that is what they want to delete. and then they submit to delete. does that make sense?
_____________________________
Dan
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 13:46:51
its on our intranet....so just are employee's will be able to add there names and delete.......so your saying then i should have a page where they can pick there name...and after selecting there name...they can click a botton and it will delete it???
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 13:54:39
exactly...here is a simple one i did in an asp course i just took ..you need two files..first to display the name so they can select one: <!--#Include virtual="adovbs.inc"-->
<%
Dim Conn, RS
Set Conn=Server.CreateObject("ADODB.Connection")
Set RS=Server.CreateObject("ADODB.Recordset")
Conn.Open
RS.Open "contact",Conn,adOpenkeyset,adLockoptimistic,adCmdTable
%>
<html><head><title>Delete From My Database</title></head>
<body>
<form method="post" action="deleteprocess.asp">
<select name="deleteit">
<%
Do Until RS.EOF%>
<option
value="<%=RS.Fields("contact_id")%>"><%=RS.Fields("lname")%></option>
<%RS.MoveNext
Loop%>
</select>
<input type="submit" name="delete" value="Delete Name">
</form>
<%
RS.close
Set RS=Nothing
Conn.close
Set Conn=Nothing
%>
</body></html>
and the second file to do the deletion based upon their selection <!--#Include virtual="adovbs.inc"-->
<%
Dim Conn,id,numaffected,statement
id=Request.Form("deleteit")
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.Open
statement="DELETE FROM contact WHERE contact_id=" & id
Conn.Execute statement,numaffected,adCmdText
Conn.close
Set Conn=Nothing
%> not real sophisticated but it will give you an idea
_____________________________
Dan
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 13:57:09
yea, very good point - notice in mine, it is grabbing the id and putting that into the value to be processed but displaying the name for the user to select. based upon spookys point, you would want to display last name and first name
_____________________________
Dan
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 14:20:51
ok....i'm getting this error....Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified with that code dpf.....what did i leave out??
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 14:24:22
oh..i deleted my part about the connection method.. are you using a dsn to connect? if you are, see where it says Conn,open? you follow that with a space and the name of your dsn, i think in quotes <edit> i cant remember.. it might be Conn.open "DSN = dsnName" not sure
< Message edited by dpf -- 12/30/2004 14:32:36 >
_____________________________
Dan
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 14:35:20
man...i'm making this hard for you.....but i'm not using DSN....
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 14:43:45
not making it hard for me.. you have no idea how much it thrills me to have justa tad of asp knowledge and be able to help..... until I run out of ideas and spooky or rdouglas or someone has to bail us out.. lol.. ok no dsn.. you said an intranet. in the first code you posted, you had this: <!--#INCLUDE VIRTUAL="/includes/connection.asp" --> does that include a connection string? maybe you just need to put that at the top. what kind of database?
_____________________________
Dan
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 15:54:26
did you modify this: quote:
value="<%=RS.Fields("contact_id")%>"><%=RS.Fields("lname")%></option> to match your db names? contact_id and lname were names from my db
_____________________________
Dan
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 15:58:58
yeah i changed them to LastName....my fields are.... ID, LastName, FirstName, Office
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 16:02:34
ok... in this, "contact" is my table name..did you change it to the name of your table (not the db name)?quote:
Conn.Open RS.Open "contact",Conn,adOpenkeyset,adLockoptimistic,adCmdTable
_____________________________
Dan
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 16:17:45
This is what I did...<!--#INCLUDE VIRTUAL="/includes/connection.asp" -->
<%
Dim Conn, RS
Set Conn=Server.CreateObject("ADODB.Connection")
Set RS=Server.CreateObject("ADODB.Recordset")
Conn.Open
RS.Open "PatientRegistration",Conn,adOpenkeyset,adLockoptimistic,adCmdTable
%>
<html><head><title>Delete From My Database</title></head>
<body>
<form method="post" action="deleteprocess.asp">
<select name="deleteit">
<%
Do Until RS.EOF%>
<option
value="<%=RS.Fields("ID")%>"><%=RS.Fields("LastName")%></option>
<%RS.MoveNext
Loop%>
</select>
<input type="submit" name="delete" value="Delete Name">
</form>
<%
RS.close
Set RS=Nothing
Conn.close
Set Conn=Nothing
%>
</body></html>
|
|
|
|
dpf
Posts: 7120 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: delete record - 12/30/2004 16:22:38
frankly I am stumped - sorry - have to wait for one of the experts to come along.. good luck
_____________________________
Dan
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 16:25:53
ok ..thanks
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 17:09:05
<!--#INCLUDE VIRTUAL="/includes/connection.asp" -->
<%
Dim Conn,id,numaffected,statement
id=Request.Form("deleteit")
Set Conn=Server.CreateObject("ADODB.Connection")
Conn.Open
statement="DELETE FROM LastName WHERE LastName_id=" & id
Conn.Execute statement,numaffected,adCmdText
Conn.close
Set Conn=Nothing
%> and this is the error i'm getting..... Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified /deleteit.asp, line 8
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 12/30/2004 19:30:00
this is my include file code.....<%
DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("/fpdb/class.mdb") & ";"
objConn.Open
%>
how do I add it in...
|
|
|
|
Brandon
Posts: 433 Joined: 7/13/2004 From: Indiana, US Status: offline
|
RE: delete record - 1/5/2005 1:53:49
Thanks for all your help guys....got it working....
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|