public List <SysTableModel> GetAll(string dbName) { //var sql = (dbName.ToLower() == "master") ? $"USE {dbName}; select name, object_id, type from sys.tables;" : $"USE {dbName}; SELECT * FROM sys.objects WHERE TYPE='U' or TYPE='V';"; var sql = $"USE {dbName}; SELECT name, object_id, type FROM sys.objects WHERE TYPE='U' or TYPE='V' order by name;"; using (SqlCommand command = new SqlCommand(sql)) { var dt = dbAccess.GetDataTable(command); List <SysTableModel> listSysTable = new List <SysTableModel>(); SysTableModel sysTable; foreach (DataRow dataRow in dt.Rows) { sysTable = new SysTableModel(); sysTable.Name = dataRow[0].ToString(); sysTable.ObjectId = dataRow[1].ToString(); sysTable.Type = dataRow[2].ToString(); listSysTable.Add(sysTable); } return(listSysTable); } }
public List <SysDatabaseModel> GetAll() { using (SqlCommand command = new SqlCommand("SELECT name, database_id FROM sys.databases;")) { var dt = dbAccess.GetDataTable(command); List <SysDatabaseModel> listSysDatabase = new List <SysDatabaseModel>(); SysDatabaseModel sysDatabase; foreach (DataRow dataRow in dt.Rows) { sysDatabase = new SysDatabaseModel(); sysDatabase.Name = dataRow[0].ToString(); sysDatabase.DatabaseId = Convert.ToInt32(dataRow[1]); listSysDatabase.Add(sysDatabase); } return(listSysDatabase); } }