Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am wanting to get all table names inside a particular MDF file and use them in a for each statement to send to multiple tables at one time. However, I can not seem to find any documentation that shows how to use a for each statement with an MDF file.

Any suggestions?

What I have tried:

Tried to do
For each tab as datatable in mybase
however, I could not seem to get any connections to the database tables.
Posted
Updated 13-Aug-18 11:24am
Comments
RedDk 13-Aug-18 17:13pm    
No way that way. But think about it. How time consuming would it be to CREATE DATABASE twoMybase from the .mdf, use the system enumerator (sysinfo/similar) to get all the information you're after, dump it into another table then DELETE the DATABASE?
Member 11856456 13-Aug-18 17:58pm    
I completely understand I am trying to come up with a decent method that will not use a ton of memory. As it stands I can use a bulk copy statement to pull into one table, is it possible to split that data up to other tables?
Patrice T 13-Aug-18 17:29pm    
What magic are you using to read the mdf file?
Member 11856456 13-Aug-18 17:56pm    
I just use a simple SQL query to connect to the database. But The reason I was asking this question is I thought that if I had all the table names I could run a for each statement and send data that was relevant to each table to split the information.

1 solution

foreach just iterates over any collection of items where the collection implements the IEnumerable interface.

It's up to you to provide that collection. You're going to have to write the code to attach the database file to an appropriate server, then query that server for the tables in the database. It's up to you to convert the returned information into something usable then build a collection from the data to hand to a foreach.

You are NEVER going to find anything that says how to "use a foreach with a MDF file". There's just no sense to that.

You have to break the problem down into smaller components, starting with "how to I attach and .MDF file?", then moving on to "how do query the database engine to return a list of tables for a database?", ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900