首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

Access导出xml解决方法

2012-03-31 
Access导出xml数据库中有多个表,eg,SMT_Folder_Table,SMT_Object_Table,SMT_Control_Table等,关系是:SMT_O

Access导出xml
数据库中有多个表,eg,SMT_Folder_Table,SMT_Object_Table,SMT_Control_Table等,关系是:SMT_Object_Table.ParentID=SMT_Folder_Table.ID, SMT_Control_Table.ParentID=SMT_Object_Table.ID
怎样写sql语句,将这三个表中的内容读出来写成想xml文件?

现在我的代码是这样的

C# code
DataTable dt = new DataTable();            using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"E:\Project\Copy of SmartTesterNet\SmartTesterNet.Web\App_Data\MR_System_All.mdb"))            {                try                {                    OleDbCommand cmd = new OleDbCommand("select * from SMT_Folder_Table,SMT_Object_Table where SMT_Object_Table.ParentID =SMT_Folder_Table.ID", conn);                    OleDbDataAdapter oda = new OleDbDataAdapter(cmd);                    oda.Fill(dt);                    dt.TableName = "SMT_Folder_Table";                    cmd.Dispose();                }                catch (Exception ex)                {                    conn.Close();                    throw new Exception(ex.Message);                }            }            dt.WriteXml(@"E:\Project\Copy of SmartTesterNet\SmartTesterNet.Web\App_Data\123.xml",true); 


得到的结果是以下格式
XML code
- <SMT_Folder_Table>  <SMT_Folder_Table.No>65</SMT_Folder_Table.No>   <SMT_Folder_Table.ID>ID_20090326_86116451</SMT_Folder_Table.ID>   <SMT_Folder_Table.ParentID>ID_20090326_95313513</SMT_Folder_Table.ParentID>   <SMT_Folder_Table.Name>TextEdit_Scene</SMT_Folder_Table.Name>   <SMT_Folder_Table.Select>False</SMT_Folder_Table.Select>   <SMT_Folder_Table.Sort>False</SMT_Folder_Table.Sort>   <SMT_Object_Table.No>383</SMT_Object_Table.No>   <SMT_Object_Table.ID>ID_20090318_6714558</SMT_Object_Table.ID>   <SMT_Object_Table.ParentID>ID_20090326_86116451</SMT_Object_Table.ParentID>   <SMT_Object_Table.Name>TextEdit_FRM</SMT_Object_Table.Name>   <SMT_Object_Table.Select>False</SMT_Object_Table.Select>   <SMT_Object_Table.Sort>True</SMT_Object_Table.Sort>   </SMT_Folder_Table>


但是我希望的吧,是能这样子
XML code
- <SMT_Folder_Table>  <SMT_Folder_Table.No>65</SMT_Folder_Table.No>   <SMT_Folder_Table.ID>ID_20090326_86116451</SMT_Folder_Table.ID>   <SMT_Folder_Table.ParentID>ID_20090326_95313513</SMT_Folder_Table.ParentID>   <SMT_Folder_Table.Name>TextEdit_Scene</SMT_Folder_Table.Name>   <SMT_Folder_Table.Select>False</SMT_Folder_Table.Select>   <SMT_Folder_Table.Sort>False</SMT_Folder_Table.Sort>       -<SMT_Object_Table.No>383</SMT_Object_Table.No>        <SMT_Object_Table.ID>ID_20090318_6714558</SMT_Object_Table.ID>        <SMT_Object_Table.ParentID>ID_20090326_86116451</SMT_Object_Table.ParentID>        <SMT_Object_Table.Name>TextEdit_FRM</SMT_Object_Table.Name>        <SMT_Object_Table.Select>False</SMT_Object_Table.Select>        <SMT_Object_Table.Sort>True</SMT_Object_Table.Sort>   </SMT_Folder_Table>


多谢各位大侠了

[解决办法]
下面这不是正确的XML结构,所以也不必费心了。

- <SMT_Folder_Table>
<SMT_Folder_Table.No>65</SMT_Folder_Table.No> 
<SMT_Folder_Table.ID>ID_20090326_86116451</SMT_Folder_Table.ID> 
<SMT_Folder_Table.ParentID>ID_20090326_95313513</SMT_Folder_Table.ParentID> 


<SMT_Folder_Table.Name>TextEdit_Scene</SMT_Folder_Table.Name> 
<SMT_Folder_Table.Select>False</SMT_Folder_Table.Select> 
<SMT_Folder_Table.Sort>False</SMT_Folder_Table.Sort>
-<SMT_Object_Table.No>383</SMT_Object_Table.No> 
<SMT_Object_Table.ID>ID_20090318_6714558</SMT_Object_Table.ID> 
<SMT_Object_Table.ParentID>ID_20090326_86116451</SMT_Object_Table.ParentID> 
<SMT_Object_Table.Name>TextEdit_FRM</SMT_Object_Table.Name> 
<SMT_Object_Table.Select>False</SMT_Object_Table.Select> 
<SMT_Object_Table.Sort>True</SMT_Object_Table.Sort>
</SMT_Folder_Table>

热点排行