public static IEnumerable<SpatialColumnInfo> GetTables(SqlConnection connection) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_TYPE = 'BASE TABLE'"; SqlDataReader reader = command.ExecuteReader(); List<SpatialColumnInfo> tables = new List<SpatialColumnInfo>(); while (reader.Read()) { string name = reader.GetString(0); SpatialColumnInfo table = new SpatialColumnInfo(); table.TableName = name; tables.Add(table); } connection.Close(); return tables; }
public static IEnumerable <SpatialColumnInfo> GetTables(SqlConnection connection) { connection.Open(); SqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT TABLE_NAME FROM information_schema.tables WHERE TABLE_TYPE = 'BASE TABLE'"; SqlDataReader reader = command.ExecuteReader(); List <SpatialColumnInfo> tables = new List <SpatialColumnInfo>(); while (reader.Read()) { string name = reader.GetString(0); SpatialColumnInfo table = new SpatialColumnInfo(); table.TableName = name; tables.Add(table); } connection.Close(); return(tables); }
/// <summary> /// Drop all tables from <paramref name="connection"/> /// </summary> /// <param name="connection">A SQL connection.</param> /// <param name="tables">List of tables that should be dropped from the database.</param> public static void DropTables(SqlConnection connection, SpatialColumnInfo table) { connection.Open(); SqlCommand command = connection.CreateCommand(); try { command.CommandText = string.Format("DROP TABLE [{0}]", table.TableName); command.ExecuteNonQuery(); } catch (SqlException ex) { if (ex.Message.StartsWith("Cannot drop")) { // TODO Add error reporting and logging } } connection.Close(); }