Example #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            tableColumns = (Dictionary<string, List<DB.Column>>)Session["tableColumns"];
            if (null == tableColumns) return;
            var dbo = new DB.DBCalls();

            tableColumns.ToList().ForEach(table =>
            {
                var query = "alter table [" + client + "].[" + table.Key + "] add ";
                table.Value.ForEach(column =>
                {
                    query += "[" + column.ColumnName + "] " + column.DataType.ToString();
                    if ((column.DataType == System.Data.SqlDbType.VarChar) || (column.DataType == System.Data.SqlDbType.NVarChar) || (column.DataType == System.Data.SqlDbType.Char) || (column.DataType == System.Data.SqlDbType.Char) || (column.DataType == System.Data.SqlDbType.NChar))
                    {
                        query += "(" + column.Length.ToString() + ")";
                    }
                    query += (column.IsNullable) ? " null " : " not null ";
                    query +=  (string.IsNullOrEmpty(column.DefaultValue)) ? "" : " default '" + column.DefaultValue + "'";
                    query += ", ";
                });
                query = query.Remove(query.LastIndexOf(","), 2);
                try
                {
                    dbo.ExecuteString(query);
                }
                catch (System.Data.SqlClient.SqlException sqlE)
                {
                }
            });
        }