How to iterate through the database tables and get the column and row values using ADO.NET Entity Data model

Posted on 2012-08-30
Last Modified: 2012-09-03
Hi ,
       I am using a ADO.NET entity data model. I would like to loop through all the database tables and get the column name and row values. I am partially able to achieve this.

Currently I use the code

Object LinqObject = new Table1();

But I would like to use part of code below in which tableName is a string which has the name of the database table. As I have these table names in a list I would like to loop through.

foreach(ExItem tableName in List1)
 Object LinqObject = Activator.CreateInstance(tableName, null);

//For each field in the database (or property in Linq object)
foreach (PropertyInfo pi in LinqObject.GetType().GetProperties())
     String ColumnName = pi.Name;

Open in new window

I get the error "Could not load file or assembly 'Table1 or one of its dependencies. The system cannot find the file specified." at Object LinqObject = Activator.CreateInstance(tableName, null);

How can I  solve this issue
Question by:anjana81
    LVL 96

    Accepted Solution

    First of all, Activator.CreateInstance needs to be able find the type, and it needs information.  Usually, you would need a fully-qualified assembly name, especially when going into separate assemblies.

    Second, I would love to hear about the reason for this type of requirement...

    Author Closing Comment

    Hi this requirement was to loop though certain tables and create an xml with the column names and row values. It worked by giving the fully qualified assembly name now. Thanks..

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now