<%
If Request.ServerVariables( "REQUEST_METHOD" ) = "POST" Then
strSQL = "TRUNCATE TABLE " & request("table"
set objConn = server.createobject("adodb.connection"
objConn.Open Application("connectString"
objConn.execute(strSQL)
alertStr = request("table" & " has been erased."
end if
%>
<script>
if ("<%=alertStr%>" != ""{
alert ("<%=alertStr%>"
}
function verify(){
uSure= confirm("Are you sure that you want to remove all data from the table?"
if (uSure){
document.form1.submit()
}
}
</script>
<form name=form1>
<input name="table">
<input type=button value="Erase Table" onClick="verify()">
</form> ----------------------------------------------------------------- Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
If you are doing this with a whole form on the page, why don't you add a checkbox that says "Erase Table". If the user checks it, then truncate the table on the form handler page. If you want a button to erase the table, you will have to repopulate the whole form (you can't erase the table client-side, so you would have to recall the page...). I can give you more help. If you need it, just let me know. ----------------------------------------------------------------- Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
Ok, one problem and warning:
Problem: mwolf's code above will delete the table itself, not just the contents. If you wre just looking to delete the contents of the table, but leave the structure intact, you should just do an unqualified "DELETE FROM Tablename" for your SQL String.
Warning: Be very very very sure before you write in code that will allow a user to delete a table, do not leave any possibility for allowing them to select the table and so on unless this is a temporary table, otherwise they may end up directing it (either through maliciousness or stupidity) to a non-temporary table, and leaving you without an important table and wishing you had a recovery for it.
TRUNCATE TABLE is functionally identical to DELETE statement with no WHERE clause: both remove all rows in the table. But TRUNCATE TABLE is faster and uses fewer system and transaction log resources than DELETE.
----------------------------------------------------------------- Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.