這個問題是最有可能很簡單,但我想提出一個數據集,並嘗試使用的XmlTextWriter問題XML和數據集
現在,當我救我的數據集將其保存到一個文件,然後嘗試讀取它會讀取表名稱,但顯示行爲0?所以看來我的作家不是在寫表格的行?
任何人都知道我可以解決這個問題嗎?
public static DataSet liveData = new DataSet();
public static DataTable players = new DataTable("Players");
public static void WriteSchemaWithXmlTextWriter()
{
// Set the file path and name. Modify this for your purposes.
string filename = "Schema.xml";
// Create a FileStream object with the file path and name.
System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Create);
// Create a new XmlTextWriter object with the FileStream.
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream, System.Text.Encoding.Unicode);
// Write the schema into the DataSet and close the reader.
liveData.WriteXmlSchema(writer);
writer.Close();
}
public static void ReadSchemaFromXmlTextReader()
{
// Set the file path and name. Modify this for your purposes.
string filename = "Schema.xml";
// Create a FileStream object with the file path and name.
System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Open);
// Create a new XmlTextReader object with the FileStream.
System.Xml.XmlTextReader xmlReader = new System.Xml.XmlTextReader(stream);
// Read the schema into the DataSet and close the reader.
liveData.ReadXmlSchema(xmlReader);
Console.WriteLine("y: {0}", liveData.Tables["Players"].Rows.Count);
xmlReader.Close();
}
感謝您對您的幫助提前:)
什麼是'liveData'? – EZI
道歉我切斷了一些我的代碼:) – Marca
public static DataSet liveData = new DataSet(); public static DataTable players = new DataTable(「Players」); – Marca