Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get table column names and the values

b4c4c151-e055-4b81-88d8-e779046fec70Feb 7 2016 — edited Feb 7 2016

I have a table and some of that columns i need to take it to my dropdown list.and i need to show that values in dropdown list also.In my idea i get that column name to the dropdownlist Text field and that numbers to the dropdown list value filed.

My Dropdown i need to looks like this.(this is for userId 100)<br>

pic2.png

My Table.

table.PNG

This is Oracle database and i tried to get it both text and value looks like this.. but unfortunately.. i cant get the value.( eg.. if Volvo has 3 ).

In here using below query i can get that Column names,But i need both column names and respective values.

My Code

public List\<AllocModel> GetAllocationByUserId(string UserId)

    {

        try

        {

            DatabaseProviderFactory factory = new DatabaseProviderFactory();

            Database db = factory.Create("DefaultCon");

            con.Open();

            string Query = @"SELECT column\_name

                             FROM USER\_TAB\_COLUMNS

                             WHERE table\_name = 'TBL\_ALLOC' AND column\_name LIKE 'EZ\_%'";

           // string Query = @"SELECT column\_name

                          //   FROM USER\_TAB\_COLUMNS T ,TBL\_ALLOC TX

                          //   WHERE T.table\_name = 'TBL\_ALLOC' AND T.column\_name LIKE 'EZ\_%' AND (TX.UserId =: TX.UserId)";

            cmd = db.GetSqlStringCommand(Query);

           // db.AddInParameter(cmd, "TX.UserId", DbType.String, UserId);

            var dx = db.ExecuteDataSet(cmd);

            var dd = dx.Tables\[0\].AsEnumerable().Select(x => new AllocModel

            {

                 COLUMN\_NAME = x.Field\<string>("COLUMN\_NAME") // Column names comes to here.

            });

            var allocNos = dd.ToList();

            return allocNos;

        }

        catch (Exception ex)

        {

            throw;

        }

    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 6 2016
Added on Feb 7 2016
5 comments
865 views