Link to home
Start Free TrialLog in
Avatar of anjana81
anjana81

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of anjana81
anjana81

ASKER

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