Using ADO, how to detect a table exists..
-
Hiya I am using ADO and need to be able to detect if a table already exists. If the table exists, I need to drop the table and create this new table. This is my code so far: // create table and don't allow any zero value records sqlcmd.Format( "CREATE TABLE Pxhsinv (Invoice varchar(30) NOT NULL,Invoice_Record varchar(8000) NOT NULL)" ); // execute the sql string pConnection->Execute(_bstr_t(sqlcmd), RecordsAffected, 1); // empty string sqlcmd.Empty(); How do I detect if the table exists already.. Thanks.
-
Hiya I am using ADO and need to be able to detect if a table already exists. If the table exists, I need to drop the table and create this new table. This is my code so far: // create table and don't allow any zero value records sqlcmd.Format( "CREATE TABLE Pxhsinv (Invoice varchar(30) NOT NULL,Invoice_Record varchar(8000) NOT NULL)" ); // execute the sql string pConnection->Execute(_bstr_t(sqlcmd), RecordsAffected, 1); // empty string sqlcmd.Empty(); How do I detect if the table exists already.. Thanks.
I think that if the table already exists, the database will throw an error. Could you trap it?
-
Hiya I am using ADO and need to be able to detect if a table already exists. If the table exists, I need to drop the table and create this new table. This is my code so far: // create table and don't allow any zero value records sqlcmd.Format( "CREATE TABLE Pxhsinv (Invoice varchar(30) NOT NULL,Invoice_Record varchar(8000) NOT NULL)" ); // execute the sql string pConnection->Execute(_bstr_t(sqlcmd), RecordsAffected, 1); // empty string sqlcmd.Empty(); How do I detect if the table exists already.. Thanks.
Run the Query -
Select name from sysobjects where name like 'Pxhsinv' and type = 'U'
If this query gives some record in the resultset, the table is present else not. Gaurav