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文件?
现在我的代码是这样的
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);
- <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>
- <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>
<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>