Azavea.NijPredictivePolicing.Common.DB.DataClient.HasTable C# (CSharp) Method

HasTable() public static method

Checks the schema of the database to see if the given table is present
public static HasTable ( DbConnection conn, IDataClient client, string tablename ) : bool
conn System.Data.Common.DbConnection
client IDataClient
tablename string
return bool
        public static bool HasTable(DbConnection conn, IDataClient client, string tablename)
        {
            try
            {
                var dt = conn.GetSchema("Tables");
                foreach (DataRow row in dt.Rows)
                {
                    if ((row["TABLE_NAME"] as string) == (string)tablename)
                    {
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error("Error while looking for table", ex);
            }
            return false;
        }