private Column GetColumns(DataRow row)
        {
            var column = new Column();
            column.Name = row[1] as string;
            column.Type = row[2] as string;
            column.Length = Convert.ToInt16(row[3]);

            column.IsNullable = Convert.ToInt32(row[4]) == 0;

            column.Scale = Convert.ToByte(row[5]);
            column.Precision = Convert.ToByte(row[6]);
            column.IsPrimaryKey = Convert.ToInt32(row[7]) == 1;
            column.Default = row[8] as string;

            if (column.Default.StartsWith("(("))
                column.Default = column.Default.Substring(1, column.Default.Length - 2);

            return column;
        }
        private List<Column> GetColumns(SqlDataReader reader)
        {
            var list = new List<Column>();

            while (reader.Read())
            {
                var column = new Column();
                column.Name = reader.GetString(0);
                column.Type = reader.GetString(1);
                column.Length = reader.GetInt16(2);
                column.IsNullable = reader.GetInt32(3) == 0;
                if (reader.FieldCount >= 5)
                {
                    column.Scale = reader.GetByte(4);
                    column.Precision = reader.GetByte(5);
                    column.IsPrimaryKey = reader.GetInt32(6) == 1;
                    column.Default = reader.GetString(7);

                    if (column.Default.StartsWith("(("))
                        column.Default = column.Default.Substring(1, column.Default.Length - 2);
                }

                list.Add(column);
            }

            return list;
        }
Ejemplo n.º 3
0
        private List<Column> GetColumns(string sql)
        {
            var list = new List<Column>();

            using (var com = con.CreateCommand())
            {
                com.CommandText = sql;

                using (var reader = com.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var column = new Column();
                        column.Name = reader.GetString(0);
                        column.Type = reader.GetString(1);
                        column.Length = reader.GetInt16(2);
                        column.IsNullable = reader.GetInt32(3) == 0;
                        if (reader.FieldCount >= 5)
                        {
                            column.Scale = reader.GetByte(4);
                            column.Precision = reader.GetByte(5);
                            column.IsPrimaryKey = reader.GetInt32(6) == 1;
                            column.Default = reader.GetString(7);

                            if (column.Default.StartsWith("(("))
                                column.Default = column.Default.Substring(1, column.Default.Length - 2);
                        }

                        list.Add(column);
                    }

                    reader.Close();
                }
            }

            return list;
        }