Click to See Complete Forum and Search --> : Table Existing
GMV
February 9th, 2003, 02:13 PM
Hi,
Could any body tell me the proper way to find a table
whether it exists or not.
I use code:
OleDbConnection dbConnection = new OleDbConnection(ConnectionString);
string InsertQuery = "CREATE TABLE Processed (Cod INTEGER, ProcessDate DATETIME)";
OleDbCommand dbCreateCommand = new OleDbCommand(InsertQuery, dbConnection);
dbDeggyConnection.Open();
dbCreateCommand.ExecuteNonQuery();
But, if table already exist I get an error.
Thx in advance.
pareshgh
February 10th, 2003, 11:12 AM
the easiest sol. would be keeping try catch blocks
OleDbConnection dbConnection = new OleDbConnection(ConnectionString);
string InsertQuery = "CREATE TABLE Processed (Cod INTEGER, ProcessDate DATETIME)";
OleDbCommand dbCreateCommand ;
try
{
dbCreateCommand = new OleDbCommand(InsertQuery, dbConnection);
}catch
{
}
dbDeggyConnection.Open();
dbCreateCommand.ExecuteNonQuery();
yes, there are other sol. also.
Paresh
GMV
February 10th, 2003, 12:28 PM
Thanks a lot
But I think it's not very good solution. May be you can get me another hints?
Maksim.
pareshgh
February 10th, 2003, 12:40 PM
you can access the table info from
a metatable
like
execute the query
SELECT * FROM sysobjects WHERE name = 'TableName'
and check for the results...
rest u know...
:D
enjoy,
Paresh
pareshgh
February 10th, 2003, 12:43 PM
forgot to give an example (i tested it on my machine)
SELECT * FROM sysobjects WHERE name = 'pro'
if exists will return with
pro 965578478 U 1 1 1610612736 0 0 0 2003-02-10 10:38:35.190 0 0 0 U 1 67 0 2003-02-10 10:38:35.190 0 0 0 0 0 0 0
these details in SQLDataReader r;
int i=0;
while(r.Read() )
{
i++
}
if( i >=1 )
{
// don't create table
}
else
{
//create table
}
:D
Paresh
GMV
February 10th, 2003, 04:53 PM
Thanks a lot
But I think it's not very good solution. May be you can get me another hints?
Maksim.
GMV
February 10th, 2003, 05:00 PM
Thanks a lot
But I think it's not very good solution. May be you can get me another hints?
Maksim.
GMV
February 10th, 2003, 05:04 PM
I'm sorry! I have problem with inet connection.
Thx a million!!!
pareshgh
February 10th, 2003, 06:04 PM
why ???
what happened...
SELECT * FROM sysobjects WHERE name = 'TableName'
should work... it gives the existance of a table.
if you are using SQL Server
did you got that..
Paresh
GMV
February 11th, 2003, 03:55 PM
Hi!
I use Microsoft Access.
I think the problem in that.
pareshgh
February 11th, 2003, 03:58 PM
yeah, look I gave you example with respect to SQL Server,
I don't know that you are having MS Access. so I think for timebeing you should go with try...catch untill 'I'/'you'/someone
finds the correct solution from access table..
rgds,
Paresh
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.