none
Question about XSD, DataSet, dataGridView, BindingSource and XML. RRS feed

  • Question

  • Dear all,

    My application is very simple, i.e. modify the XML file by playing with the dvg1 on the Winform.

    The structure of XML file that I played with is as follows,

    <S type="A">
    <p>
    <A></A>
    <B>1</B>
    <C></C>
    </p>
    <p>
    ...
    </p>
    ...
    <p>
    ...
    </p>
    </S>

    I did it in the following ADO.Net way, e.g. load XML file to the dataSet1, show the content of dataSet1 in the dvg1 (DataGridView), add new row, delete multiple rows in the dvg1 by using the relevant MenuItmes on the ContextMenu (cause I disable the property "AllowUserToAddRow"), then update the dataSet1, and save the modified dataSet1 to the previous XML file. Meanwhile, there are two bonus requirements to be done, e.g. increment the new row value of "B" by 1 automatically when adding it to the dataSet1, and save the content of the dataSet1 as the ArrayList, e.g. each row as one array in the list.

    The way that I binded the dvg1 with the XML file is as follows,

    dataSet1.ReadXml(".\\example.xml", XmlReadMode.Auto);
    dvg1.DataSource = new BindingSource(dataSet1, "p");

    Question 1. I added the dataSet1 by dragging the DataSet to the dvg1 control. Since I am not sure whether the dataSet1 should be created with the XML schema (XSD) in my case??? Therefore, I chose the typed dataSet. How shall I connect the XSD with my existing XML file, i.e. example.xml, if the XSD needs to be created?

    Question 2, Moreover, I used the following codes in the handler function of the AddpMenuItems on the ContextMenu1.

    DataRow _row = dataSet1.Tables["p"].NewRow();

    _row["A"] = "0";

    dataSet1.Tables["p"].Rows.Add(_row);

    However, I met the problem about setting the value of "B" automatically increase by 1 and set the ReadOnly value of "C" to be true, since such properties are not supported by _row. How shall I do it?

    3. Since there are several child nodes "p" with the same structure in my XML file. Shall I create several dataTables to read their values?

    4. How shall I delete multiple rows from dataSet1, then update its content to dvg1? By updating, shall I create the other dataSet2, then point the dvg1 dataSource to it , then load the dvg1 one more time?

    5. About the saving the updated dataSet1 to previous XML file, can I use the WriteXML() method from dataSet1 directly? I met the problem about it with the error "inconsistent token structure" before. Is there any method supported to read each row in the DataSet table to the ArrayList or JaggedArray?

    Although my questions may be a little bit weak, I really need some helps, especially after I looked through the tutorials but still be confused by the proposed questions.

    Thanks for the helps!

    B.W.

    B-D
    Saturday, July 14, 2007 12:33 AM