Original: http: //aspalliance.com/articleViewer.aspx aId = 477 & pId = -1 Author:? Andrew Mooney translation: Mencius Chapter E [download the source code http://aspalliance.com/download/477/ASPAlliance477.zip] Xml2OleDb Introduction XML is the best way to share data in the Internet, and data in XML format can be easily integrated into different web applications. But what if you want to insert an XML file into the database? XML2OL2OLDB will explain to the OLEDB database, such as SQL Server, Access, Excel, Visual FoxPro, FoxPro, and DBase, etc. Insert XML files, etc. First, load the XML file into the DataSet and get the first table. This table is the DataTable we have to join the database; Next, remove the extension of the XML file, the file name removes the extension will be the table name used in our database . If the XML format is inaccurate, an error will be reported, and an example in the source code has an example of XML file format. See Authors.xml // Loading the XML files we submit to DataSetDataSetXml.Readxml (httpcontext.current.server.mappath (textboxxml.text)); // Get the first table DataTableXML = DataSetXml.tables [0]; / / Generate a table name tablename = textBoxxml.text.Substring (0, textboxxml.text.length -4); once the XML load is successful, first check if there is data (ROWS), then check if the database exists, if not The existence is created; then the data is then inserted into the database from XML. / / Check if there is a data existence (ROWS) if (DataTableXML.Rows.count> 0) Creating a database table Create a database connection to get the database schema information we have to add a table.
// create a database connection, open the database, the database table schema information obtained OleDbConnection oledbConn = new OleDbConnection (textBoxOleDb.Text); oledbConn.Open (); DataTable schemaTable = oledbConn.GetOleDbSchemaTable (OleDbSchemaGuid.Tables, new object [] {null, NULL, TABLENAME, "Table"}); // Check if the table exists, if there is a record IF (Schematable.Rows.Count <1) sqlcmd = "Create Table" TableName "("; for (INT i = 0; i