AzurePoolCrossDbGenerator/DbAccess.cs
/// <summary>
/// Returns a comma-separated list of table column names, excluding identity columns
/// </summary>
/// <param name="connectionString"></param>
/// <param name="tableName"></param>
/// <returns></returns>
Returns a comma-separated list of table column names, excluding identity columns
Returns a comma - separated list of table column names excluding identity columns
public static string GetInsertableTableColumnNames(string connectionString, string tableName)
        {
            string queryString = @"select c.name from sys.all_columns c, sys.tables t 
                                    where c.object_id = t.object_id and t.name = @table_name and is_identity = 0
                                    order by column_id";
            StringBuilder sb = new StringBuilder();
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@table_name", tableName);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        string colName = reader["name"].ToString();
                        sb.Append("[");
                        sb.Append(colName);
                        sb.Append("]");
                        sb.AppendLine(",");
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return sb.ToString().TrimEnd(trailingChars.ToCharArray());
        }
public static string GetInsertableTableColumnNames ( string connectionString , string tableName ) { string queryString = @"select c.name from sys.all_columns c, sys.tables t 
                                    where c.object_id = t.object_id and t.name = @table_name and is_identity = 0
                                    order by column_id" ; StringBuilder sb = new StringBuilder ( ) ; using ( SqlConnection connection = new SqlConnection ( connectionString ) ) { SqlCommand command = new SqlCommand ( queryString , connection ) ; command . Parameters . AddWithValue ( " " , tableName ) ; connection . Open ( ) ; SqlDataReader reader = command . ExecuteReader ( ) ; try { while ( reader . Read ( ) ) { string colName = reader [ " " ] . ToString ( ) ; sb . Append ( " " ) ; sb . Append ( colName ) ; sb . Append ( " " ) ; sb . AppendLine ( " " ) ; } } finally { reader . Close ( ) ; } } return sb . ToString ( ) . TrimEnd ( trailingChars . ToCharArray ( ) ) ; }
Returns a comma-separated list of table column names, excluding identity columns
Returns a comma - separated list of table column names excluding identity columns
// select column definitions from INFORMATION_SCHEMA.COLUMNS // read the column definition // add to the list // remove trailing , and new line
None
connectionString
string
None
tableName
string
None