• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 890
  • Last Modified:

How to get the value from database row wise using ado.net entity framework

Hi,  
     I am new in using ADO.NET entity data model. I would like to extract the column name and the corresponding row values from the sql server database for my program.
   
 I use the code below
         
     
   MyPgmEntities context = new MyPgmEntities();
         var customer= from c in context.tblcustomer select c;            
         Object LinqObject = new tblcustomer ();
           foreach (var  c in customer)
           {
                foreach (PropertyInfo pi in LinqObject.GetType().GetProperties())
                {                        
               //Get Column Name                          
               string sAtt = pi.Name;
               //Get row value for the corresponding column name 'sAtt'
                ????
               }
           }

Open in new window


Using the above code I am able to get the column name. But I would like to know how to loop through and get the corresponding row values in the database.

Thanks
0
anjana81
Asked:
anjana81
1 Solution
 
käµfm³d 👽Commented:
It should just be c.Name for the value.

You typically (if not always) set up your entity to model the table(s) the data is coming from. This means if you have a table named Customer and that table has a column named Name, then in C# you have a class named Customer, with a property called Name.
0
 
anjana81Author Commented:
As mentioned above if I give c.Name I can have the row value. But as I would like to loop through all the columns and get the column name and the corresponding row values. How can I achieve this ? for example something like c.sAtt  where sAtt is a string that  has the column name. This is because I have 40 columns and its better to get these row values in a loop rather than specifing c.Col1Name,c.col2Name,c.col3Name etc...

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now