Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reliably check if a table exists
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Reliably check if a table exists
Versions des environnements
Environment:
C# 2.0
Database:
MS SQL Server
Divers
Thread ID:
01227222
Message ID:
01227222
Vues:
85
What is the most reliable method of testing if a table exists?
I am using SQL Server compact edition.

Currently doing this:
protected bool TableExists(string tableName)
{
    string sql =  "SELECT table_name FROM INFORMATION_SCHEMA.tables WHERE table_name = '" + tableName + "'";
    bool exists = false;
    using (SqlCeConnection cn = new SqlCeConnection(this.connectionString))
    {
        using (SqlCeCommand cm = new SqlCeCommand(sql, cn))
        {
            cn.Open();
            SqlCeResultSet r = cm.ExecuteResultSet(ResultSetOptions.Scrollable);
            exists = r.HasRows;
        }
    }
    return exists;
}
Just like to ensure I'm using the most reliable test
- Craig

"If you're not prepared to be wrong, you will never come up with anything original."
- Sir Ken Robinson
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform