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

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

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
0
anjana81
Asked:
anjana81
1 Solution
 
Bob LearnedCommented:
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...
0
 
anjana81Author Commented:
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..
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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