ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 5th, 2009, 06:30 PM
austince austince is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: Pensacola, FL
Posts: 13 austince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 19 sec
Reputation Power: 0
Send a message via Google Talk to austince Send a message via Skype to austince
JScript - Database - General - Drop Table IF Exist

How do I drop a table if exist using ASP Javascript. It is probably something simple but I have been staring at the monitor for awhile with out a solution.

Buy a beer for whoever answers first.

Reply With Quote
  #2  
Old November 6th, 2009, 07:47 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 3,461 sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Day 16 h 50 m 26 sec
Reputation Power: 1806
Quote:
Originally Posted by austince
How do I drop a table if exist using ASP Javascript. It is probably something simple but I have been staring at the monitor for awhile with out a solution.

Buy a beer for whoever answers first.

Hi, and welcome to the forums, what type of database are you using, as I think this will dictate the syntax of your query?

heres an example using sqlserver.

Reply With Quote
  #3  
Old November 6th, 2009, 09:48 AM
austince austince is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: Pensacola, FL
Posts: 13 austince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 19 sec
Reputation Power: 0
Send a message via Google Talk to austince Send a message via Skype to austince
Good morning sync_or_swim,

I looked the example previously and this what I came up with:
[code]
<!--- MS Access Connection --->
<!--#include file="Connections/access.asp"-->


<%
var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";
conn.Execute
%>
[code]

The error that I get back is "Command text was not set for the command object."

Thank you ahead of time for your help on this.

Reply With Quote
  #4  
Old November 7th, 2009, 02:36 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
You are not sql to the command object.
Code:
var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.CommandText = sql
conn.CommandType=adCmdText
conn.Execute
You can read here for info
http://www.asp101.com/articles/wrox/asp30/26100902.asp
__________________
Laziness is my religion and Sunday is my God

Get the Mantra!

Reply With Quote
  #5  
Old November 9th, 2009, 10:43 AM
austince austince is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: Pensacola, FL
Posts: 13 austince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 19 sec
Reputation Power: 0
Send a message via Google Talk to austince Send a message via Skype to austince
@Sync_Or_System: MS Access right now before being transitioned to MS SQL 2005

@Micky: When I run the following code:

var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.CommandText = sql;
conn.CommandType=adCmdText;
conn.Execute;

It comes up with the following error:

'adCmdText' is undefined

When I did research in other forums and the stated that if I bracketed the table it would execute. No success.

I tried to drop the conn.Command=adCmdText and tried to see what happens and I get this error:

Invalid SQL State; Expected Delete, Insert, Procedure, select, or update

Doing research so I don't sound like a dofus on this and for better understanding, the adCmdTxt is trying to evaluate CommandText (which in this case, "conn.CommandText = sql") has a textual definition of a command or stored procedure call. Am I correct? Or way of base?

Reply With Quote
  #6  
Old November 9th, 2009, 10:56 AM
Jonathan8146 Jonathan8146 is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Posts: 1,708 Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 3 h 50 m 45 sec
Reputation Power: 177
Quote:
Originally Posted by austince
@Sync_Or_System: MS Access right now before being transitioned to MS SQL 2005

@Micky: When I run the following code:

var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.CommandText = sql;
conn.CommandType=adCmdText;
conn.Execute;

It comes up with the following error:

'adCmdText' is undefined

When I did research in other forums and the stated that if I bracketed the table it would execute. No success.

I tried to drop the conn.Command=adCmdText and tried to see what happens and I get this error:

Invalid SQL State; Expected Delete, Insert, Procedure, select, or update

Doing research so I don't sound like a dofus on this and for better understanding, the adCmdTxt is trying to evaluate CommandText (which in this case, "conn.CommandText = sql") has a textual definition of a command or stored procedure call. Am I correct? Or way of base?


Code:
var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.Execute sql 

Reply With Quote
  #7  
Old November 9th, 2009, 11:10 AM
austince austince is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: Pensacola, FL
Posts: 13 austince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 19 sec
Reputation Power: 0
Send a message via Google Talk to austince Send a message via Skype to austince
Still comes with the error:

"Command text was not set for the command object"



Quote:
Originally Posted by Jonathan8146
Code:
var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.Execute sql 

Reply With Quote
  #8  
Old November 10th, 2009, 02:17 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
Quote:
Originally Posted by austince
@Sync_Or_System: MS Access right now before being transitioned to MS SQL 2005

@Micky: When I run the following code:

var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.CommandText = sql;
conn.CommandType=adCmdText;
conn.Execute;

It comes up with the following error:

'adCmdText' is undefined

When I did research in other forums and the stated that if I bracketed the table it would execute. No success.

I tried to drop the conn.Command=adCmdText and tried to see what happens and I get this error:

Invalid SQL State; Expected Delete, Insert, Procedure, select, or update

Doing research so I don't sound like a dofus on this and for better understanding, the adCmdTxt is trying to evaluate CommandText (which in this case, "conn.CommandText = sql") has a textual definition of a command or stored procedure call. Am I correct? Or way of base?
So you havent included adovbs.inc file........ in that file value for adCmdText is defined.

You can have such code in your asp page to define its value.
Code:
Dim adCmdText
adCmdText = 1

Reply With Quote
  #9  
Old November 11th, 2009, 01:03 PM
austince austince is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: Pensacola, FL
Posts: 13 austince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 19 sec
Reputation Power: 0
Send a message via Google Talk to austince Send a message via Skype to austince
Question

Sorry that I did not reply sooner. Had Tropical Lynda going though my backyard.

Micky's Version

Code:
var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.CommandText = sql
conn.CommandType=adCmdText
conn.Execute


Jonathan8146's Version

Code:
var conn, sql
set conn = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_STRING;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.Execute sql 


Austin's version

Code:
var adCmdText = 1 
var conn, sql 
conn  = Server.CreateObject("ADODB.Command");
conn.ActiveConnection = MM_access_string;
sql = "if EXISTS (SELECT * FROM MCN_Read) BEGIN DROP TABLE MCN_Read END";

conn.CommandText = sql;
conn.CommandType = adCmdText;
conn.Execute;


My version get's the following error:

Microsoft OLE DB Provider for ODBC Driver '8004e14'

[Microsoft][ODBC Microsoft Access Driver] Invalid SQL Statement; expected 'DELETE', 'INSERT', 'PROCEDURE','SELECT' or 'UPDATE'.

The code stops on the conn.Execute. I tried to run the SQL statement in Access 2007 and came up with the same error. Am I trying to force Access something that it can not do?

Reply With Quote
  #10  
Old November 12th, 2009, 02:23 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
I am not too sure if Access 2007 can do it.
Have a look at this link which has code to use IF EXISTS

http://www.dmxzone.com/go?4615

Reply With Quote
  #11  
Old November 12th, 2009, 03:34 AM
Jonathan8146 Jonathan8146 is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Posts: 1,708 Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 3 h 50 m 45 sec
Reputation Power: 177
Not sure if this is the best way to do this, but when using Access I check one of the "hidden/system" tables to see if a table exists
Code:
strSQL = "SELECT Name "_
	  & "FROM  MSysObjects "_
	  & "WHERE NAME = 'tablename';"

Reply With Quote
  #12  
Old November 12th, 2009, 02:27 PM
austince austince is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: Pensacola, FL
Posts: 13 austince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 19 sec
Reputation Power: 0
Send a message via Google Talk to austince Send a message via Skype to austince
Coming closure to a solution

Code:
<%
var sql =("Select * From MCN_Read")
var adCmdText = 1
var conn = Server.CreateObject("ADODB.Command")
conn.ActiveConnection = MM_access_STRING;

if (sql = true)
{
sql = "DROP TABLE_Read";
conn.CommandText = sql;
conn.CommandType = adCmdText;
conn.Execute;
}

else (sql = false)
{
sql = ("Select NULL")
conn.CommandText = sql;
conn.CommandType = adCmdText;
conn.Execute;
}

%>


It finds MCN_Read if exists and drops it. What I am having difficulty with now is if the MCN_Read doesn't exist, continue on with the execution of thre rest of the . The error code that I get back 'Table 'MCN_Read' does not exist.

Reply With Quote
  #13  
Old November 16th, 2009, 12:19 PM
austince austince is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: Pensacola, FL
Posts: 13 austince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 19 sec
Reputation Power: 0
Send a message via Google Talk to austince Send a message via Skype to austince
Anyone out there?

Reply With Quote
  #14  
Old November 18th, 2009, 10:03 AM
austince austince is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Location: Pensacola, FL
Posts: 13 austince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 6 m 19 sec
Reputation Power: 0
Send a message via Google Talk to austince Send a message via Skype to austince
Update

Code:
<%
var sql = "Select * From MCN_Read"
var adCmdText = 1
var conn = Server.CreateObject("ADODB.Command")
conn.ActiveConnection = MM_access_STRING;

conn.CommandText = sql;
conn.CommandType = adCmdText;
var oRS = conn.Execute;
if (!oRS.EOF)
{
sql = "DROP TABLE_Read";
conn.CommandText = sql;
conn.CommandType = adCmdText;
conn.Execute;
}
%>


The error that I receive is an MS Access error "The database engine could not lock table 'MCN_Read' because it is already in use by another person or process". Code stops to execute on line "conn.Execute;".

I look forward to a response and I will continue search for a solution. My understanding is that EOF is locking up the table when it should be releasing it after the "conn.Execute". Am I correct or way off base?

Reply With Quote
  #15  
Old November 18th, 2009, 10:29 AM
Jonathan8146 Jonathan8146 is offline
Contributing User
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Posts: 1,708 Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level)Jonathan8146 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 3 h 50 m 45 sec
Reputation Power: 177
Quote:
Originally Posted by austince
Code:
<%
var sql = "Select * From MCN_Read"
var adCmdText = 1
var conn = Server.CreateObject("ADODB.Command")
conn.ActiveConnection = MM_access_STRING;

conn.CommandText = sql;
conn.CommandType = adCmdText;
var oRS = conn.Execute;
if (!oRS.EOF)
{
sql = "DROP TABLE_Read";
conn.CommandText = sql;
conn.CommandType = adCmdText;
conn.Execute;
}
%>


The error that I receive is an MS Access error "The database engine could not lock table 'MCN_Read' because it is already in use by another person or process". Code stops to execute on line "conn.Execute;".

I look forward to a response and I will continue search for a solution. My understanding is that EOF is locking up the table when it should be releasing it after the "conn.Execute". Am I correct or way off base?


I think you may need to close the connection, i.e. oRS.Close, after checking if EOF

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > JScript - Database - General - Drop Table IF Exist


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek