XML to Database

How can I create a database table based on an XML schema and populate it with the XML data. Currently, I am using ReadXml to display the data in a datagrid via a virtual dataset. Can I write the data out into a table or text file without having to define each field and node It looks just like I want it in the datagrid display I just need to get that into an actual file. The following code is what I am using now:

fileName = ofdGetXML.get_FileName();

System.String filePathNew = fileName;

dsRegNew.ReadXml(filePathNew);

dataGridReg.set_DataSource(dsRegNew);

dataGridReg.set_DataMember("SomeDocument");

dataGridReg.set_CaptionText(dataGridReg.get_DataMember());

Thanks.



Answer this question

XML to Database

  • SXUgomper

    Hi,

    Also for updating database with dataset the suggestion in the following post will be helpfull for you http://www.dotnet247.com/247reference/msgs/1/6283.aspx

    regards,

    Raj Thilak


  • SRasheed

    Hi,

    Nice trick. Sorry but I can't make the DataAdapter.Update() work. Could you be more precise please

    Besides, it seems like you need to add the line da.SelectCommand = cmd; in the code above to make it work.

    System.String cnstr = "Provider=MSDAOSP;Data Source=MSXML2.DSOControl;";

    System.String sql = "C:\\products.xml";

    OleDbConnection cn = new OleDbConnection(cnstr);

    OleDbCommand cmd = new OleDbCommand(sql, cn);

    OleDbDataAdapter da = new OleDbDataAdapter();

    da.SelectCommand = cmd;

    DataTable dt = new DataTable();

    da.Fill(dT);

  • Tanny

    I'm going to assume your xml is standard element xml with no attributes or schema.

    With this being the case, you are already there in terms of having a database.

    System.String cnstr = "Provider=MSDAOSP;Data Source=MSXML2.DSOControl;";

    System.String sql = "C:\\products.xml";

    OleDbConnection cn = new OleDbConnection(cnstr);

    OleDbCommand cmd = new OleDbCommand(sql, cn);

    OleDbDataAdapter da = new OleDbDataAdapter();

    DataTable dt = new DataTable();

    da.Fill(dT);

    At this point you can do whatever you want to with the data. Build a new database using ADOX, populate the DataGridView directly or fill non-bindable objecs with all your information.

    HTH


  • XML to Database