|
|
 |
|
October 10th, 2004, 10:08 PM
|
#1
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
Delete All Row (Select All Row Using Radio Button)
Ok guys...
Let say I have an ASP page that will displays all my data in the database.
Each row, I provide a DELETE button so the specific row can be deleted!
This method can be very hard if we are consider to delete all the data with ONE CLICK!
Can anybody guide me on how to use a RADIO BUTTON to select all the row and at the end of the page, there is a DELETE button that will delete whatever row that I have selected to be deleted ??:
This is the display database page...
Code:
<%
While ((Repeat1__numRows <> 0) AND (NOT admin.EOF))
%>
<tr bgcolor="#E6E6E6">
<td width="182" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("name").Value)%></font></div>
</td>
<td width="120" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center" style="width: 6; height: 0"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("ID").Value)%></font></div>
</td>
<td width="181" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("email").Value)%></font></div>
</td>
<td width="115" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("username").Value)%></font></div>
</td>
<td width="116" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("password").Value)%></font></td>
<td width="51" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
">Delete
</font></div>
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
admin.MoveNext()
Wend
%>
|
|
|
October 11th, 2004, 06:21 AM
|
#2
|
|
Most Reputable Member
Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0
|
hard?
put this at the top of your page:
Code:
<%
' connect rs to database
For Each record In Request("Delete")
rs.Open "DELETE * FROM [Table Name] WHERE (ID=" & record & ")"
Next ' record
%>
obviously, connect the recordset to the database and put in your table name
then use this link to delete a record:
heres the full code:
Code:
<%
While ((Repeat1__numRows <> 0) AND (NOT admin.EOF))
%>
<tr bgcolor="#E6E6E6">
<td width="182" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("name").Value)%></font></div>
</td>
<td width="120" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center" style="width: 6; height: 0"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("ID").Value)%></font></div>
</td>
<td width="181" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("email").Value)%></font></div>
</td>
<td width="115" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("username").Value)%></font></div>
</td>
<td width="116" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("password").Value)%></font></td>
<td width="51" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<input type=submit name=Delete value="delete">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
?delete=<%=admin("ID")%>">Delete
</font></div>
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
admin.MoveNext()
Wend
%>
</FORM>
|
|
|
October 12th, 2004, 09:46 PM
|
#3
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
This is my database connection which will display all data in the recordset!
Code:
<%
set admin = Server.CreateObject("ADODB.Recordset")
admin.ActiveConnection = MM_AdminRegister_STRING
admin.Source = "SELECT * FROM userlistSort"
admin.CursorType = 0
admin.CursorLocation = 2
admin.LockType = 3
admin.Open()
admin_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
admin_numRows = admin_numRows + Repeat1__numRows
%>
Looping display database entry (below)...
This code is not working...I mean the delete function is still not working.
What I want to do is, when the user select the row using the radio button, and then later click the DELETE ALL button at the end of the page.
It will then delete all the selected row
<span style="color:red"> Can anybody look at my DELETE ALL button?</span id="red">
Code:
<%
While ((Repeat1__numRows <> 0) AND (NOT admin.EOF))
%>
<tr bgcolor="#E6E6E6">
<td width="182" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("name").Value)%></font></div>
</td>
<td width="120" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center" style="width: 6; height: 0"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("ID").Value)%></font></div>
</td>
<td width="181" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("email").Value)%></font></div>
</td>
<td width="115" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("username").Value)%></font></div>
</td>
<td width="116" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(admin.Fields.Item("password").Value)%></font>
</td>
<td width="51" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input type="radio" name="radiobutton" value="radiobutton">
</font></div>
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
admin.MoveNext()
Wend
%>
</table>
<div align="right">DELETE ALL</div>
</center>
</div>
</form>
|
|
|
October 13th, 2004, 11:06 PM
|
#4
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
|
|
|
October 14th, 2004, 06:59 AM
|
#5
|
|
Most Reputable Member
Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0
|
note:
radio button only allows one selection so you have to use CHECKBOX instead, i.e.:
<input type=checkbox name=delete
then, it's the same thing I posted before:
1. put this at the top of you page:
Code:
<%
' connect rs to database
For Each record In Request("Delete")
rs.Open "DELETE * FROM [Table Name] WHERE (ID=" & record & ")"
Next ' record
%>
2. put this at the beginning of each row, so the user can select which records should be deleted
Code:
<input type=checkbox name=delete value="<%=admin("ID")%>">
3. use this link deletes one record (put it at the end of each row, within the loop)
4. the submit button will delete all selected records:
<input type=submit value="Delete Selected Records">
|
|
|
October 14th, 2004, 09:51 PM
|
#6
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
Hai spinal...
When you write this, <input type=checkbox name=delete value=" <%=admin("ID")%>">,is it reffering to my recordset for adnmin ID,because my code for that is <%=(admin.Fields.Item("ID").Value)%>. I am a little bit confuse here
One more..
For the code below, do I have to change anything there?
I dont understand the "SCRIPT_NAME"?
One last thing...
This is my rs connection, so..you mean I just have to put the code inside it like this??? Can you guide me if i am wrong?
i dont understand this part: WHERE (ID=" & record & ")"
Code:
<!!--My recordset to display all data inside userlist.mdb-->
<%
set admin = Server.CreateObject("ADODB.Recordset")
admin.ActiveConnection = MM_AdminRegister_STRING
admin.Source = "SELECT * FROM userlist"
admin.CursorType = 0
admin.CursorLocation = 2
admin.LockType = 3
admin.Open()
admin_numRows = 0
For Each record In Request("Delete")
admin.Open "DELETE * FROM userlist WHERE (ID=" & record & ")"
Next
%>
|
|
|
October 15th, 2004, 05:53 AM
|
#7
|
|
Most Reputable Member
Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0
|
<%=(admin.Fields.Item("ID").Value)%> and <%=admin("ID")%> are the same thing.
then, you must deledt the records before you load the records again so:
Code:
<!!--My recordset to display all data inside userlist.mdb-->
<%
set admin = Server.CreateObject("ADODB.Recordset")
admin.ActiveConnection = MM_AdminRegister_STRING
'this goes first, delete the records
For Each record In Request("Delete")
admin.Open "DELETE * FROM userlist WHERE (ID=" & record & ")"
Next
' then open your recordset
admin.Source = "SELECT * FROM userlist"
admin.CursorType = 0
admin.CursorLocation = 2
admin.LockType = 3
admin.Open()
admin_numRows = 0
' you could do it all in one line like this:
' this is the same as your 6 lines above
admin.Open "SELECT * FROM userlist", 0, 2, 3
|
|
|
October 15th, 2004, 10:41 PM
|
#8
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
Thanx spinal..
Let me try it out first.
I'll let you know the result.
|
|
|
October 17th, 2004, 07:20 AM
|
#9
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
Hai spinal....
I have this problem while executing the delete operation!
Can you look at my code PLEASE.....
THIS IS THE ERROR THAT I GET
Technical Information (for support personnel)
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
/admin/ViewList_RegisteredLecturer. asp, line 8
Line 8 is the: viewLec.Open "DELETE * FROM userlist WHERE (username=" & record & ")"
HERE IS MY DATABASE CONNECTION
Code:
<%
set viewLec = Server.CreateObject("ADODB.Recordset")
viewLec.ActiveConnection = MM_lecturer_STRING
For Each record In Request("Delete")
viewLec.Open "DELETE * FROM userlist WHERE (username=" & record & ")"
Next
viewLec.Source = "SELECT * FROM userlistSort"
viewLec.CursorType = 0
viewLec.CursorLocation = 2
viewLec.LockType = 3
viewLec.Open()
viewLec_numRows = 0
%>
Here is my full coding for displaying the userlistSort.mdb database query.
Code:
<Form name="lecturer">
<table width="100%" bgcolor="#587698" style="border-collapse: collapse">
..
..
..
<%
While ((Repeat1__numRows <> 0) AND (NOT viewLec.EOF))
%>
<tr bgcolor="#E6E6E6">
<td width="44" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center">
<!--This is my checkbox button. I put at the beginning of each row. We set the value to be the unique data inside our database, can you tell me the purpose of this!
<input type="checkbox" name="delete" value="<%=(viewLec.Fields.Item("username").Value)%>">
</div>
</td>
<td width="165" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center" style="width: 6; height: 0"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(viewLec.Fields.Item("fullname").Value)%></font></div>
</td>
<td width="129" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(viewLec.Fields.Item("ID").Value)%></font></div>
</td>
<td width="162" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(viewLec.Fields.Item("email").Value)%></font></div>
</td>
<td width="148" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(viewLec.Fields.Item("username").Value)%></font></td>
<td width="161" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=(viewLec.Fields.Item("password").Value)%></font></div>
</td>
<td width="148" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
?delete=<%=(viewLec.Fields.Item("username").Value)%>">Delete Me![/b]</font>
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
viewLec.MoveNext()
Wend
%>
</table>
<input type=submit value="Delete Selected Records">
</Form>
</body>
</html>
<%
viewLec.Close()
%>
Basically, the method that I used before this is like this:
when i click the delete button (at the end of each row), it will bring to another page where the delete operation will be done.
What I want to do now is, when i click the delete button, the selected row to be deleted will dissapear automatically without going to another page.
Can you help me with the problem that i am facing here.
|
|
|
October 17th, 2004, 11:17 AM
|
#10
|
|
Elite Veteran
SuperMember
Join Date: Jul 2003
Location: Southern UK
Age: 35
Posts: 3,126
Thanks: 28
Thanked 22 Times in 19 Posts
|
What you want to do is very possible.... but I think you should solve your current problem first in order to learn from it. You appear from the above to be deleting records based on a username.... which must surely be a text type database field.... yet you refer to it as if it were a number... user the following:- [b]viewLec.Open "DELETE * FROM userlist WHERE (username='" & record & "')"[b]
However, may I point out that you really should be deleting records based on the unique identifier (Primary Key).... personally I would use the UserID (or whatever you've called it)
<blockquote id="quote" class="ffs">quote:<hr height="1" noshade="noshade" id="quote" />What I want to do now is, when i click the delete button, the selected row to be deleted will dissapear automatically without going to another page.
Can you help me with the problem that i am facing here.<hr height="1" noshade="noshade" id="quote" /></blockquote id="quote">This is possible. However, you will be placing a critical part of your application's functionality in the hands of javascript.... and this is NEVER a good idea. I thought I would give you the info before you make a decision. Is there anything wrong with spawning a new window using target=_blank for the delete process? This way, the record WILL be deleted regardless of the clients support for javascript.
Some things above for you to think about.
|
|
|
October 17th, 2004, 11:12 PM
|
#11
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
Hai Rob and spinal...
So that mean, when I change the (refer to database field for the delete purpose) "username" to my "no"-(unique auto number in my database) then the code will work?
<span style="color:red">Please help he guys...I have spent more than a week to do this simple task!:sad:</span id="red">
I have a database table called userlist containing Fields: no (autoNumber & primary key also), ID, username (primary Key), password, fullname and email. For now I have refer the "username" fiels instead of the "no" fiels to delete my record...
Ok...this code now refer to the autonumber primary key field "no" in my database..Can you look at it and comment if I have a syntax error or wrong coding technique please.....
Code:
<%@LANGUAGE="VBSCRIPT"%>
<%
set viewLec = Server.CreateObject("ADODB.Recordset")
viewLec.ActiveConnection = MM_lecturer_STRING
For Each record In Request("Delete")
viewLec.Open "DELETE * FROM userlist WHERE (no=" & record & ")"
Next
viewLec.Source = "SELECT * FROM userlist"
viewLec.CursorType = 0
viewLec.CursorLocation = 2
viewLec.LockType = 3
viewLec.Open()
viewLec_numRows = 0
%>
<%
Dim Repeat1__numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
viewLec_numRows = viewLec_numRows + Repeat1__numRows
%>
<html>
<head>
<title>View Registered Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body topmargin="0" bgcolor="#F1F8FC">
<form name="DeleteChecked">
<table border="1" bordercolor="#F1F8FC" width="100%" id="AutoNumber2" height="1">
<tr bgcolor="#0D5692">
<td width="44" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"></font>
</td>
<td width="165" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Lecturer Name</font>
</td>
<td width="129" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Lecturer ID</font>
</td>
<td width="162" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Email Address</font>
</td>
<td width="148" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Username</font>
</td>
<td width="161" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Password</font>
</td>
<td width="148" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Delete</font>
</td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT viewLec.EOF))
%>
<tr bgcolor="#E6E6E6">
<td width="44" bordercolor="#0D5692" height="10" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center">
<input type="checkbox" name="delete" value="<%=(viewLec.Fields.Item("no").Value)%>">
</div>
</td>
<td width="165" bordercolor="#0D5692" height="10" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center" style="width: 6; height: 0">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%=(viewLec.Fields.Item("fullname").Value)%></font>
</div>
</td>
<td width="129" bordercolor="#0D5692" height="10" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%=(viewLec.Fields.Item("ID").Value)%></font>
</div>
</td>
<td width="162" bordercolor="#0D5692" height="10" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%=(viewLec.Fields.Item("email").Value)%></font>
</div>
</td>
<td width="148" bordercolor="#0D5692" height="10" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%=(viewLec.Fields.Item("username").Value)%></font>
</td>
<td width="161" bordercolor="#0D5692" height="10" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
<div align="center">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%=(viewLec.Fields.Item("password").Value)%></font>
</div>
</td>
<td width="148" bordercolor="#0D5692" height="10" align="center" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#FFFFFF">
?delete=<%=(viewLec.Fields.Item("no").Value)%>">Delete Me!
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
viewLec.MoveNext()
Wend
%>
</table>
<input type=submit value="Delete Selected Records">
</center>
</div>
</Form>
</body>
</html>
<%
viewLec.Close()
%>
Here is the sample preview of the above code. I have uploaded them in the internet so you can get the idea of my page looks like
http://www40.brinkster.com/evanevie/
Hai spinal and Rob..Do I have to change anything in this code?
What is the "SCRIPT_NAME" refer to?
<font size="1"> <A href="<%=Request.ServerVariables("SCRIPT_NAME")%>? delete=<%=(viewLec.Fields.Item("no").Value)%>">Del ete Me!</A></font id="size1">
|
|
|
October 19th, 2004, 01:30 PM
|
#12
|
|
Most Reputable Member
Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0
|
1. you missed the ' around the username (assuming it's a string)
For Each record In Request("Delete")
viewLec.Open "DELETE * FROM userlist WHERE (username='" & record & "')"
viewLec.Close ' close the recordset before you try to open it again
Next
2. <%=Request.ServerVariables("SCRIPT_NAME")%> is the name of the script you're currently viewing so that the link will work, whatever the page is called....
|
|
|
October 19th, 2004, 09:53 PM
|
#13
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
You mean...all i have to modify here is the "SCRIPT_NAME"??
Are you reffering "SCRIPT_NAME" to be my page name?
I dont understand spinal
Ok...basically...the code that you gave me will be working on that page without any <form action=""> right?
Can you give me some sample
So..I have to add the ' around the & record if the identifier is a number? Am I right?
If it a string, eg: username, dont use that ' symbol?
<blockquote id="quote" class="ffs">quote:<hr height="1" noshade="noshade" id="quote" />For Each record In Request("Delete")
viewLec.Open "DELETE * FROM userlist WHERE (username='" & record & "')"
viewLec.Close ' close the recordset before you try to open it again
Next<hr height="1" noshade="noshade" id="quote" /></blockquote id="quote">
<span style="color urple">For now, I am trying to delete using my "no field" in my database which is an auto number primary key, I am not using the "username" field anymore </span id="purple">
<blockquote id="quote" class="ffs">quote:<hr height="1" noshade="noshade" id="quote" />For Each record In Request("Delete")<hr height="1" noshade="noshade" id="quote" /></blockquote id="quote">
Is "Delete" a function or does it refer to any id name?
|
|
|
October 20th, 2004, 04:36 AM
|
#14
|
|
Most Reputable Member
Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0
|
Request("Delete") fetches all the submitted values for the checkbox names "Delete"
<%=Request.ServerVariables("SCRIPT_NAME")%> RETRIEVES THE CURRENT PAGE ADDRESS, SO WHATEVER YOU CALLED YOUR PAGE, LEAVE THIS ALONE!
you have to enclose strings with ', not numbers!!!!!!!!!!!
|
|
|
October 20th, 2004, 07:22 AM
|
#15
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
I am sorry spinal...:sad:
I am very blank here. I am very not happy until I successfully complete this function. Could you spent more of your time with me please.
Actually I have done my asp page using Macromedia Ultradev4. You can just click without typing any code to it (auto generate codes) Maybe that is the reason why I am having trouble with CODING....
Basically...I am in the process of learning that auto generated code.
I have studied lots of code from the internet especially this link that I got from planetsourcecode...Its kind of easy but still when I follow every single step, it still not working! Check Deleting Record Using CheckBox
I have posted my file that consist of the Display page, Delete page and also my Database...All of them is working except for the <span style="color:red">Delete using checkbox</span id="red"> and the <span style="color:red">Delete by row</span id="red">. Could you download it and run them in your PC and take a look whats wrong with the code, please...
<font size="1">Right click and save target as..</font id="size1">
DOWNLOAD MY CODE HERE
I hope that you can take a look at it spinal...
I would be grateful if you help me. I know this is a simple problem for you guys....yet I am still in my dark life trying to achieve them.
|
|
|
October 20th, 2004, 11:21 AM
|
#16
|
|
Most Reputable Member
Join Date: Mar 2004
Location: Good Ol'London
Age: 24
Posts: 1,684
Thanks: 1
Thanked 4 Times in 4 Posts
Rep Altering Power: 0
|
there!
Code:
<%@ LANGUAGE=VBSCRIPT %>
<% Option Explicit %>
<%
Dim conn,viewLec,record
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("database\lecturerLogin.mdb"))
set viewLec = Server.CreateObject("ADODB.recordset")
Dim lecturer
Response.Write "LECTURERS TO DELETE: " & Request("delete") & "
"
For Each lecturer In Request("delete")
Response.Write "deleting lecturer " & lecturer & " (DELETE * from userlist WHERE (no = " & lecturer & ")) ...
"
viewLec.Open "DELETE * from userlist WHERE (no = " & lecturer & ")", conn,3,3
viewLec.Close
Next
viewLec.Open "SELECT * from userlist", conn
'set viewLec = conn.execute("SELECT * from userlist") <!-Other way to display data->
%>
<%
Dim Repeat1__numRows,viewLec_numRows
Repeat1__numRows = -1
Dim Repeat1__index
Repeat1__index = 0
viewLec_numRows = viewLec_numRows + Repeat1__numRows
%>
<html>
<head>
<title>View Registered Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body topmargin="0" bgcolor="#F1F8FC">
<Form Name="Form" Action="<%=Request.ServerVariables("SCRIPT_NAME")%>" method="post">
<div align="center">
<center>
<table border="1" cellspacing="1" width="100%" id="AutoNumber3" bordercolor="#0D5692" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#587698" style="border-collapse: collapse">
<tr>
<td width="50%" bgcolor="#587698" bordercolor="#000000" height="10" bordercolorlight="#587698" bordercolordark="#587698"><font size="1" face="Verdana" color="#FFFFFF">Main
Page > Register Lecturer > View Registered Lecturer</font></td>
<td width="50%" bgcolor="#587698" bordercolor="#000000" height="10" bordercolorlight="#587698" bordercolordark="#587698">
<p align="right"><font face="Verdana" size="1" color="#FFFFFF">[<%=FormatDateTime(Date,1)%>]</font>
</td>
</tr>
</table>
</center>
</div>
<div align="center">
<center>
<table border="1" bordercolor="#F1F8FC" width="100%" id="AutoNumber2" height="54">
<tr>
<td width="44" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376" height="19">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Check</font></td>
<td width="165" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376" height="19">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Lecturer
Name</font></td>
<td width="129" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376" height="19"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Lecturer
ID</font></td>
<td width="162" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376" height="19">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Email
Address</font></td>
<td width="148" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376" height="19"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Username</font></td>
<td width="161" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376" height="19">
<font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Password</font></font></td>
<td width="148" bordercolor="#0D5692" align="center" bordercolorlight="#164376" bordercolordark="#164376" bgcolor="#164376" height="19"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Delete</font></td>
</tr>
<%
Dim RowCount,RowColour
RowCount = 0
While ((Repeat1__numRows <> 0) AND (NOT viewLec.EOF))
If (RowCount Mod 2)=0 Then RowColour = "#FFFFFF" Else RowColour = "#CEDFED"
RowCount = RowCount + 1
%>
<tr style="background-color:<%=RowColour%>">
<td width="44" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000">
<div align="center">
<input type="checkbox" name="delete" value="<%=viewLec("no")%>">
</div>
</td>
<td width="165" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000">
<div align="center" style="width: 6; height: 0"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><%=viewLec("fullname")%></font></div>
</td>
<td width="129" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%Response.Write (viewLec("ID"))%>
</font></div>
</td>
<td width="162" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%Response.Write (viewLec("email"))%>
</font></div>
</td>
<td width="148" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%Response.Write (viewLec("username"))%>
</font></td>
<td width="161" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000">
<div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%Response.Write (viewLec("password"))%>
</font></div>
</td>
<td width="148" bordercolor="#0D5692" height="1" align="center" bordercolorlight="#000000" bordercolordark="#000000">
<font face="Verdana, Arial, Helvetica, sans-serif" style="font-size: 9pt">
?delete=<%=viewLec("no")%>">delete
</font></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
viewLec.MoveNext()
Wend
%>
</table>
<input type="submit" value="Delete Selected">
</center>
</div>
</Form>
</body>
</html>
<%
viewLec.Close()
%>
|
|
|
October 22nd, 2004, 05:26 AM
|
#17
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
Hai spinal...
Did you test the delete operation? I mean both of them, using Text Link DELETE and delete using Checkbox?
When I tried to delete the data using the Delete text:
as well as the delete selected checkbox... I got this error!
It say that the operation is not allowed when the object is closed!
What do that mean?
The error refer to the viewLec.Close...
Code:
<%@ LANGUAGE=VBSCRIPT %>
<% Option Explicit %>
<%
Dim conn,viewLec,record
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("database\lecturerLogin.mdb"))
set viewLec = Server.CreateObject("ADODB.recordset")
Dim lecturer
Response.Write "LECTURERS TO DELETE: " & Request("delete") & "
"
For Each lecturer In Request("delete")
Response.Write "deleting lecturer " & lecturer & " (DELETE * from userlist WHERE (no = " & lecturer & ")) ...
"
viewLec.Open "DELETE * from userlist WHERE (no = " & lecturer & ")", conn,3,3
viewLec.Close
Next
viewLec.Open "SELECT * from userlist", conn
'set viewLec = conn.execute("SELECT * from userlist") <!-Other way to display data->
%>
This is the error that I get!
<blockquote id="quote" class="ffs">quote:<hr height="1" noshade="noshade" id="quote" />
Technical Information (for support personnel)
Error Type:
ADODB.Recordset (0x800A0E78)
<span style="color:red"> Operation is not allowed when the object is closed.</span id="red">
/ViewList_RegisteredLecturer. asp, line 16
Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Page:
GET /ViewList_RegisteredLecturer. asp
Time:
22 October 2004, 16:22:51
More information:
Microsoft Support
<hr height="1" noshade="noshade" id="quote" /></blockquote id="quote">
|
|
|
October 22nd, 2004, 11:00 AM
|
#18
|
|
Elite Veteran
SuperMember
Join Date: Jul 2003
Location: Southern UK
Age: 35
Posts: 3,126
Thanks: 28
Thanked 22 Times in 19 Posts
|
you dont need to close the object when perfoming a delete.... the SQL delete command does not return a recordset.... therefore there is nothing to close.
|
|
|
October 22nd, 2004, 11:42 PM
|
#19
|
|
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Thanks: 0
Thanked 4 Times in 3 Posts
|
Hey guys...
But, when I throw this line of code away : viewLec.Close in the delete loop...
Nothing is happening! When I click the checkbox and the "Delete Selected" button..nothing is happening!
It just displaying the information (checkbox value which I clicked) of the data that I am trying to delete at the top of my page...This is the code in that delete loop...:
1. <font size="1">Response.Write "LECTURERS TO DELETE: " & Request("delete") & "
"</font id="size1">
2. <font size="1">Response.Write "deleting lecturer " & lecturer & " (DELETE * from userlist WHERE (no = " & lecturer & ")) ...
"</font id="size1">
...The delete operation is just dont happen! Is there any syntax error, do I have to change any variable in that code?
I just dont understand how the.....:
<ul>[*]<font size="1"><%=Request.ServerVariables("SCRIPT_NAME")%>?delete =<%=viewLec("no")%>"></font id="size1"> can delete the record??[*]Why does the From Action is equal to the SCRIPT_NAME as well? What is the purpose?<font size="1">
<Form Name="Form" Action="<%=Request.ServerVariables("SCRIPT_NAME")% >" method="post"></font id="size1">[*]What is the problem guys...? Help me please :sad:[/list]
|
|
|
October 23rd, 2004, 04:02 AM
|
#20
|
|
Elite Veteran
SuperMember
Join Date: Jul 2003
Location: Southern UK
Age: 35
Posts: 3,126
Thanks: 28
Thanked 22 Times in 19 Posts
|
maybe try this:-
Code:
viewLec.Open "DELETE * from userlist WHERE (no = " & request("delete")(lecturer) & ")", conn,3,3
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|