Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP to SQL

Status
Not open for further replies.

DirtDawg

IS-IT--Management
Apr 17, 2002
218
JP
Hello,


I would like to create a button on a web page that would delete all information from the specified table? Can anyone help me out?

Thanks in advance
 
<%
If Request.ServerVariables( &quot;REQUEST_METHOD&quot; ) = &quot;POST&quot; Then
strSQL = &quot;TRUNCATE TABLE &quot; & request(&quot;table&quot;)
set objConn = server.createobject(&quot;adodb.connection&quot;)
objConn.Open Application(&quot;connectString&quot;)
objConn.execute(strSQL)
alertStr = request(&quot;table&quot;) & &quot; has been erased.&quot;
end if
%>

<script>
if (&quot;<%=alertStr%>&quot; != &quot;&quot;){
alert (&quot;<%=alertStr%>&quot;)
}

function verify(){
uSure= confirm(&quot;Are you sure that you want to remove all data from the table?&quot;
if (uSure){
document.form1.submit()
}
}
</script>

<form name=form1>
<input name=&quot;table&quot;>
<input type=button value=&quot;Erase Table&quot; onClick=&quot;verify()&quot;>
</form> -----------------------------------------------------------------
[pc] Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
 
I need to get a little bit more help here is the scipt for the page

<Form Name=&quot;form&quot; Form Action = &quot;dc1.asp&quot; method=&quot;POST&quot;>
<td width=&quot;8%&quot; align=&quot;center&quot;><b>HKHKG</b></td>
<td width=&quot;8%&quot; align=&quot;center&quot;></td>
<td width=&quot;8%&quot; align=&quot;center&quot;><INPUT NAME=&quot;mtav&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;></td>
<td width=&quot;8%&quot; align=&quot;center&quot;><INPUT NAME=&quot;ldib&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
<td width=&quot;8%&quot; align=&quot;center&quot;><INPUT NAME=&quot;damg&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
<td width=&quot;8%&quot; align=&quot;center&quot;><INPUT NAME=&quot;incom&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
<td width=&quot;8%&quot; align=&quot;center&quot;><INPUT NAME=&quot;incoml&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
<td width=&quot;8%&quot; align=&quot;center&quot;><INPUT NAME=&quot;repo&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
<td width=&quot;9%&quot; align=&quot;center&quot;><INPUT NAME=&quot;pup&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
<td width=&quot;9%&quot; align=&quot;center&quot;><INPUT NAME=&quot;dof&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
<td width=&quot;9%&quot; align=&quot;center&quot;><INPUT NAME=&quot;pos&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
<td width=&quot;9%&quot; align=&quot;center&quot;><INPUT NAME=&quot;results&quot; type=&quot;text&quot; size=&quot;10&quot; VALUE=&quot;0&quot;>@</td>
</tr>
<tr>
<td width=&quot;8%&quot; align=&quot;center&quot;>@</td>
<td width=&quot;92%&quot; align=&quot;center&quot; colspan=&quot;11&quot;>
<INPUT TYPE=&quot;button&quot; VALUE=&quot; HKG +&quot; onClick=&quot;sumform1()&quot;>&nbsp;&nbsp;&nbsp;&nbsp;
<input type=&quot;submit&quot; value=&quot;Submit HKG&quot;>&nbsp;&nbsp;&nbsp;&nbsp;
<subForm>
<input name=&quot;table&quot;>
<input type=button value=&quot;Erase Table&quot; onClick=&quot;verify()&quot;>
</td>
</tr>
</subForm>
</Form>
what I would like to do is have the table name already given so that when the users press the button it will delete the table.

Thanks,
 
If you are doing this with a whole form on the page, why don't you add a checkbox that says &quot;Erase Table&quot;. 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. -----------------------------------------------------------------
[pc] 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 &quot;DELETE FROM Tablename&quot; 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.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
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.
-----------------------------------------------------------------
[pc] Be nice. It's only doing what you tell it to do.
mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top