?
Solved

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

Posted on 2012-08-23
2
Medium Priority
?
886 Views
Last Modified: 2012-08-27
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
Comment
Question by:anjana81
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1500 total points
ID: 38325882
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
 

Author Comment

by:anjana81
ID: 38328315
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question