tags:

views:

62

answers:

3

I want to create an Access database('mdb') from an xml file.

Creating empty access database is easy(I am able to do this), I am having problem in figuring out how can we create a table and populate it with data from the xml file on the fly through code.

I am using C#.

A: 

You can read the XML file into a DataSet, then populate it into your database.

DataSet ds = new DataSet();
ds.ReadXml(filename);

foreach(DataTable table in ds.Tables) {

    //Create table

    foreach(DataRow row in table.Rows) {
        //Insert rows
    }
}
Marko
A: 

That's a fairly simple outline below. How are you connecting to the MDB file? Via ADO/OLEDB you will need to issue SQL-DMO instructions such as "CREATE TABLE"
If you are using DAO via COM Interop, you can create the table programmatically via the Database.TableDefs collection.
In either case you will need to know your data types / mapping, unless you are using entirely text fields in the tables.

DataSet ds = new DataSet(); 
ds.ReadXml(filename); 

foreach(DataTable table in ds.Tables) { 

    //Create table 

    foreach(DataRow row in table.Rows) { 
        //Insert rows 
    } 
} 
Roger Willcocks
Did you really copy my answer? Nice one!
Marko
A: 

Is there a reason you're doing this programmaticly instead of using the built in feature?

Sjuul Janssen
@Sjuul: Yes, I am supposed to download a file sitting on ftp, Unzip it and populate the xml(Inside the zipped file) to an access database.Its a part of Import we are trying to do for data to be consumed by the application my company makes.I hope i have answered the question, thanks for the interest.Thanks,Sid