Hi,
I am creating a SQL Server tables programmatically in C#. I want to check first if a table exists and only if it doesn't exist, create one. I was looking around but I couln't find an easy way to do so.
Any ideas?
Thanks a lot ,
Rakefet
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
venkata naidu6 reputationPosted Mar 15, 2006, 4:08 AM EST
{
Create Table
//if table already is there,then it raise the exception.
//otherwise if table not there it create the table
}
Catch
{
do nothing
// if table already is there then only it comes.
}
Tim Heap4 reputationPosted Mar 17, 2006, 4:37 AM EST
Patricia2 reputationPosted Mar 17, 2006, 5:38 AM EST
ramesh p66 reputationPosted Apr 20, 2009, 11:53 PM EDT
try{
DbOpen();TABLE MyNewName(PersonID COUNTER PRIMARY KEY, FirstName varchar(20), LastName varchar(20))"; DBConnection););
string strStatement = "CREATE
OleDbCommand DBCommand = new OleDbCommand(strStatement,
DBCommand.ExecuteNonQuery(
DbClose();
}catch(Exception EX)
{
}
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Apr 22, 2009, 11:55 AM EDT
Hi
Instead of making a call to find out wheather table is there or not, i will issue CREATE table statement and if there are errors during this process i would like to handle it in Catch block.
Thanks
-- Vijaya Kadiyalawww
.DotNetVJ.comVijaya KadiyalaRank #1,085 · 1.8K reputationPosted Apr 22, 2009, 11:55 AM EDT
Hi
Instead of making a call to find out wheather table is there or not, i will issue CREATE table statement and if there are errors during this process i would like to handle it in Catch block.
Thanks
-- Vijaya Kadiyalawww
.DotNetVJ.com