public string SqlStatement()
        {
            string result = DatabaseNoPrimaryKey.SqlStatement();

            return(result);
            // TODO: add assertions to method DatabaseNoPrimaryKeyTest.SqlStatement()
        }
Exemple #2
0
        /// <summary>
        /// Gets the database no primary key.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <returns>the database no primary key</returns>
        public List <DatabaseNoPrimaryKey> GetDatabaseNoPrimaryKey(string database)
        {
            this.ExecuteUseDatabase(database);

            List <DatabaseNoPrimaryKey> results = new List <DatabaseNoPrimaryKey>();
            DatabaseNoPrimaryKey        resultrow;
            string sqlString = DatabaseNoPrimaryKey.SqlStatement();

            sqlString = string.Format("EXEC sp_executesql @statement = N'{0}'", sqlString.Replace("'", "''"));

            using (SqlConnection connection = new SqlConnection(this.ConnectionString))
                using (SqlCommand command = new SqlCommand(sqlString, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            resultrow = new DatabaseNoPrimaryKey(
                                reader.GetString(reader.GetOrdinal("Schema")),
                                reader.GetString(reader.GetOrdinal("Table")),
                                reader.GetInt64(reader.GetOrdinal("RowCount")));

                            results.Add(resultrow);
                        }
                    }

                    connection.Close();
                }

            return(results);
        }