Пример #1
0
        public List <string> GetDataBases()
        {
            var lista = new List <string>();

            try
            {
                //var scriptSQL = "EXEC sp_databases";Não funciona no azure
                string scriptSQL = "SELECT name, database_id, create_date FROM sys.databases ORDER BY name";
                var    dataTable = ExecuteQueryDataTable(scriptSQL);

                foreach (DataRow row in dataTable.Rows) // Loop over the rows.
                {
                    foreach (DataColumn column in dataTable.Columns)
                    {
                        var columnName = column.ColumnName.ToString();

                        if (columnName == "DATABASE_NAME")
                        {
                            var database = DataGridViewUtil.GetValueDataRow(row, columnName);
                            lista.Add(database.ToString());
                        }
                    }
                    //foreach (var item in row.ItemArray) // Loop over the items.
                    //{
                    //    Console.WriteLine(item); // Invokes ToString abstract method.
                    //}
                }
            }
            catch (SqlException)
            {
            }

            return(lista);
        }