Checking to see if a table exisits in a database

Results 1 to 2 of 2

Thread: Checking to see if a table exisits in a database

  1. #1
    Marco Valdez Guest

    Default Checking to see if a table exisits in a database

    Hello everyone, given the following simple database connection, how would I be able to check to make sure the table specified by the Query String exists? I am trying to ensure I don&#039t end up with an error when accessing a non-existent table.<BR><BR>thanks!<BR><BR>Marco<BR><BR>&#060;!--#include file="adovbs.inc" --&#062;<BR><BR>&#060;%<BR><BR>Dim tableName<BR>Dim strConnect<BR><BR>strConnect = "DSN=myDSN"<BR><BR>tableName = Request.QueryString("thattable")<BR><BR>Set objRec = Server.CreateObject ("ADODB.Recordset")<BR><BR>objRec.Open tableName, strConnect, adOpenKeyset, adLockReadOnly, adCmdTable<BR><BR>objRec.Close<BR><BR>Set objRec = Nothing<BR><BR>%&#062;<BR>

  2. #2
    Pipey Guest

    Default RE: Checking to see if a table exists in a database

    You could examine the &#039Database Schema&#039. Open a recordset like this:<BR><BR> Dim tableName<BR> Dim rsTables<BR> Dim strConnect<BR> Dim objConn<BR><BR> tableName = "mytable"<BR> strConnect = "DSN=myDSN"<BR> Set objConn = Server.CreateObject("ADODB.Connection")<BR> objConn.Open strConnect<BR> <BR> Set rsTables = objConn.OpenSchema(adSchemaTables, Array(Null, Null, Null, "TABLE"))<BR> Do Until rsTables.EOF<BR> If rsTables!TABLE_NAME = tableName Then<BR> &#039The table exists!<BR> End If<BR> rsTables.MoveNext<BR> Loop<BR> rsTables.Close<BR> objConn.Close<BR> Set rsTables = Nothing<BR> Set objConn = Nothing<BR><BR>That should do the trick nicely (although I think it may require that you have an up-to-date version of ADO installed)<BR><BR>Pipey<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •