|
 |
asptoday_discuss thread: Testing to se if a table exists?
Message #1 by "Ryan" <bz@b...> on Tue, 22 Jan 2002 03:31:11
|
|
Is it possible to test if a table with a specific name exists in a
database and return a boolean or something to find out. I am create tables
dynamically and having issues testing this possibility. I have created a
field in a seperate table to change it to true when the dynamic table is
created, but it isn't working properly. Using the error object, when the
error occurs that the table doesn't exist, how can i capture that and
correct the problem by creating a new table. I have the table creation in
a sub routine called subCreateTable(). Help...
Thanks in advanced...
Ryan
Message #2 by "Ryan" <bz@b...> on Tue, 22 Jan 2002 06:12:14
|
|
I learned about the Connection Objects OpenSchema Method. Look.
'******************
' open a connection to a db
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open hitlist_connString
' *******************************************************
' * Returns a Recordset object that contains schema information.
' * The Recordset will be opened as a read-only, static cursor.
' * The QueryType determines what columns appear in the Recordset.
' * This is the layout of the OpenSchema Method
' * connection.OpenSchema (QueryType, Criteria, SchemaID)
' *******************************************************
Set rsSchema = dbConn.OpenSchema(adSchemaColumns)
While Not rsSchema.EOF
Response.Write rsSchema("TABLE_NAME") & "<br>"
rsSchema.MoveNext
Wend
'*******************
NOTE:
In MS Access I couldn't use the Schema enumeration so I had to use "20"
instead of adSchemaColumns.
With the OpenSchema Method you can find out a lot of information about the
database schema information from the db provider. Very Powerful I think.
Let me know if there is a better way to find out if a table in a db
exists!!!
This is where I found out info on the OpenSchema Method...
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/ado270/htm/mdmthopenschema.asp
> Is it possible to test if a table with a specific name exists in a
> database and return a boolean or something to find out. I am create
tables
> dynamically and having issues testing this possibility. I have created a
> field in a seperate table to change it to true when the dynamic table is
> created, but it isn't working properly. Using the error object, when the
> error occurs that the table doesn't exist, how can i capture that and
> correct the problem by creating a new table. I have the table creation
in
> a sub routine called subCreateTable(). Help...
>
> Thanks in advanced...
> Ryan
|
|
 |