0
嗨,我有以下c#代碼,將數據保存到xml文件。將MySql查詢保存到XML文件並避免重複
問題是,它不保存我正在尋找的格式的XML,我似乎無法找到一種方法來獲取它。
C#代碼
string MyConString = "SERVER=localhost;" + "DATABASE=myvideos75;" + "UID=root;" + "PASSWORD=V0lc0m;";
string SQLSelect = "SELECT episode.idShow,tvshow.c00 as 'ShowName',episode.c12 as 'Season',XBMCPathReFact(episode.c18) as 'Path' FROM myvideos75.episode join tvshow on tvshow.idShow = episode.idShow where episode.c13 = 1 order by episode.idShow,episode.c12 ";
string _XMLFile = "test.xml";
MySqlConnection connection = new MySqlConnection(MyConString);
try
{
MySqlCommand _MySqlSelect = new MySqlCommand(SQLSelect, connection);
DataSet _DataSet1 = new DataSet("XBMC");
MySqlDataAdapter _MySqlDataAdapter1 = new MySqlDataAdapter(_MySqlSelect);
_MySqlDataAdapter1.Fill(_DataSet1,"Show");
FileStream myFs = new FileStream(_XMLFile, FileMode.OpenOrCreate, FileAccess.Write);
_DataSet1.WriteXml(myFs);
myFs.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message.ToString()); }
XML它產生
<XBMC>
<Show>
<idShow>1</idShow>
<ShowName>2 Broke Girls</ShowName>
<Season>1</Season>
<Path>\\10.0.0.3\tv\2 Broke Girls\Season1\</Path>
</Show>
<Show>
<idShow>1</idShow>
<ShowName>2 Broke Girls</ShowName>
<Season>2</Season>
<Path>\\10.0.0.3\tv\2 Broke Girls\Season 02\</Path>
</Show>
<Show>
<idShow>31</idShow>
<ShowName>Burn Notice</ShowName>
<Season>2</Season>
<Path>\\10.0.0.3\tv\Burn Notice\Season2\</Path>
</Show>
<Show>
<idShow>31</idShow>
<ShowName>Burn Notice</ShowName>
<Season>3</Season>
<Path>\\10.0.0.3\tv\Burn Notice\Season3\</Path>
</Show>
</XBMC>
我想它產生這樣的XML。
<XBMC>
<Show>
<idShow>1</idShow>
<ShowName>2 Broke Girls</ShowName>
<Seasons>
<Season>
<Number>1</Number>
<Path>\\10.0.0.3\tv\2 Broke Girls\Season1\</Path>
</Season>
<Season>
<Number>2</Number>
<Path>\\10.0.0.3\tv\2 Broke Girls\Season 02\</Path>
</Season>
</Seasons>
</Show>
<Show>
<idShow>31</idShow>
<ShowName>Burn Notice</ShowName>
<Seasons>
<Season>
<Number>2</Number>
<Path>\\10.0.0.3\tv\Burn Notice\Season2\</Path>
</Season>
<Season>
<Number>3</Number>
<Path>\\10.0.0.3\tv\Burn Notice\Season3\</Path>
</Season>
</Seasons>
</Show>
</XBMC>
SQL SELECT語句返回以下數據
謝謝您的時間