ASP And Access

  • Thread starter Thread starter Joedickenson
  • Start date Start date
J

Joedickenson

Guest
Hi

First of all sorry if i've got the wrong place!

What i would like to know is how do i get ASP to delete ALL content in My access database at a click of a button?

I can do it by getting rid of each field but i would like to do it all at once. Is this possible?

If this helps this is the backend of a tutorial i worked on(im a newbie!)

Code:
<%
'## Dimension Variables
Dim adoCon			'## Holds the database connection object
Dim rsDeleteEntry	'## Holds the recordset for the record to be deleted
Dim strSQL			'## Holds the SQL query to query the database
Dim IngRecordNo		'## Holds the record number to be deleted

'## Read in the record number to deleted
IngRecordNo = CLng(Request.QueryString("ID"))

'## Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'## Set an active connection to the Connection object using a DSN-Less Connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("shoutdb.mdb")

'## Set an active connection to the Connection object using DSN connection (untick to use)
'adoCon.Open "DSN=guestbook"

'## Create an ADO recordset object
Set rsDeleteEntry = Server.CreateObject("ADODB.Recordset")

'## Initalise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT shoutbox.* FROM shoutbox WHERE postid=" & IngRecordNo

'## Set the lock type so that the record is locked by ADO when its deleted
rsDeleteEntry.LockType = 3

'## Open recordset with the SQL query
rsDeleteEntry.Open strSQL, adoCOn

'## Delete the record from the database
rsDeleteEntry.Delete

'## Reset server object
rsDeleteEntry.Close
Set rsDeleteEntry = Nothing
Set adoCOn = Nothing

'## Return to the delete select page in case another record needs deleting
Response.Redirect "delete_select.asp"
%>

Hope thats enough

Joe
 
Why not just execute a delete query?
 
hi

Hi again,

How would i go about doing that. AS when i say a Newbie i mean im a real newbie!!! lol

many thanks

Joe
 
If you want to delete everything in a table (off the top of my head so I will not guarrenty syntax)
sSQL = "DELETE FROM tablename"
If you want to qualify what you are deleting:
sSQL = "DELETE FROM tablename WHERE some criteria"
Then you can execute this sql, typically like
ADOCONN.EXECUTE sSQL

I think
 
howdy

ahrite one problem though is where do i stick it or do i create a new database connection page and put this bit of script in there?

Thanks

joe
 
Where you put it is up to you. Depends on how your application is structured. When you want to execute this code, that is where it needs to go. How you do that is a developers issue, not knowing your applications it is kind of hard to say.
 
hey

Hey

Well if this is a better idea

is there away i can select all the data in the database. I've managed to get the delete button to delete one article at a time using something like this

Code:
action="delete_entry.asp?ID>0"

in a form which then sets off some stuff in the delete_entry.asp page

Is there away i can do something like this to allow me to select it?

What i would ideally like to do at the end of all this is be able to have some form radio buttons next to each database entry and then make it so when i tick the box and press delete it deletes just thoughs entrys.

Oh an i really appreciate your help(if i spell it right!)

Cheers

Joe
 

Users who are viewing this thread

Back
Top Bottom