Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xml和数据集的问题_C#_Xml - Fatal编程技术网

C# Xml和数据集的问题

C# Xml和数据集的问题,c#,xml,C#,Xml,这个问题很可能非常简单,但我正在创建一个数据集,并尝试使用XMLTextWriter将其保存到一个文件中 现在,当我保存数据集并尝试读取时,将读取表名,但将行显示为0?看来我的作者没有在写表格的行 有人知道我怎么解决这个问题吗 public static DataSet liveData = new DataSet(); public static DataTable players = new DataTable("Players"); public static void Wri

这个问题很可能非常简单,但我正在创建一个数据集,并尝试使用XMLTextWriter将其保存到一个文件中

现在,当我保存数据集并尝试读取时,将读取表名,但将行显示为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();
    }

提前感谢您的帮助:)

您正在编写模式,它是Xml的布局/结构,而不是实际内容

您需要使用
DataSet.WriteXml


。。。相反

抱歉,我删除了一些代码:)公共静态数据集liveData=new-DataSet();公共静态数据表播放器=新数据表(“播放器”);Marca,我想你应该使用
ReadXml
WriteXml
:)我刚刚发现它非常简单:)当你使用正确的东西时非常简单:)现在有没有一种方法对它进行编码,这样它就不能从外部修改?谢谢你allEncode什么?xml文件/数据?如果你想让人们阅读,恐怕他们可以修改它!你可以加密一个文件,但是人们需要密码才能访问它,然后他们可以修改它。