Ejemplo n.º 1
0
        public Tablemodel columntypewriter(string tablename, string dbname, string connectionstring)
        {
            _dbname    = dbname;
            _tableName = tablename;
            _conStr    = connectionstring;
            Tablemodel datamodel = new Tablemodel();

            datamodel.tablename = tablename;

            IEnumerable <Tablemodel> col = GetColumnNames();

            return(datamodel);
        }
Ejemplo n.º 2
0
        private List <Tablemodel> GetColumnNames()
        {
            List <Tablemodel> model = new List <Tablemodel>();

            using (SqlConnection connection = new SqlConnection(_conStr))
            {
                connection.Open();

                SqlCommand    command = new SqlCommand("use " + _dbname + ";" + "select top 1 * from " + _tableName, connection);
                SqlDataReader reader  = command.ExecuteReader();
                int           i       = 0;
                while (reader.Read())
                {
                    Tablemodel data = new Tablemodel();
                    data.tablename  = _tableName;
                    data.Columnname = reader.GetName(i);
                    data.Datatype   = reader.GetFieldType(i);
                    i++;
                    model.Add(data);
                }
            }
            return(model);
        }