开发者

I want to create an access database populated with data from xml file

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

Creating empty access database is easy(I a开发者_如何学运维m 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#.


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
    }
}


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 
    } 
} 


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜