public override List<SchemaTable> GetTables(string owner) { using (DbConnectionInfo cn = Db.CreateConnection()) { //owner ,table name DataTable dt = cn.GetSchema("Tables", new string[] { owner, null }); DataRowCollection drc = dt.Rows; List<SchemaTable> list = new List<SchemaTable>(drc.Count); for (int i = 0; i < drc.Count; i++) { SchemaTable item = new SchemaTable(); item.Owner = drc[i]["OWNER"].IfNull(String.Empty); item.Name = drc[i]["TABLE_NAME"].IfNull(String.Empty); //drc[i]["TYPE"] User or System list.Add(item); } return list; } }
public override List<SchemaTable> GetTables(string owner) { using (DbConnectionInfo cn = Db.CreateConnection()) { using (DbCommand cm = cn.CreateCommand()) { //catalog,schema,table name //DataTable dt = cn.GetSchema("Tables", new string[] { cn.Database, owner, null }); string sql = String.Format(@"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG={0} AND (TABLE_SCHEMA={1} OR {1}='NULL') AND TABLE_TYPE='BASE TABLE' ORDER BY TABLE_NAME", Db.GetParameterMarker("database"), Db.GetParameterMarker("owner")); cm.CommandText = sql; cm.Parameters.Add(Db.CreateParameter("database",cn.Database)); cm.Parameters.Add(Db.CreateParameter("owner",owner.IfNull("NULL"))); DataTable dt = Db.ExecQuery(cm); DataRowCollection drc = dt.Rows; List<SchemaTable> list = new List<SchemaTable>(drc.Count); for (int i = 0; i < drc.Count; i++) { //if (drc[i]["table_type"].Equals("BASE TABLE")) { SchemaTable item = new SchemaTable(); item.Owner = drc[i]["table_schema"].IfNull(String.Empty); item.Name = drc[i]["table_name"].IfNull(String.Empty); list.Add(item); } } return list; } } }