none
Columns will not load into dataset

    Question

  • dataSet1.WriteXml(saveFileDialog1.FileName, XmlWriteMode.WriteSchema);

    these 2 lines are examples not the exact code.

    dataSet1.ReadXml(openFileDialog1.FileName, XmlReadMode.ReadSchema);

    I just cant get the saved xml to load the columns back into the dataset.


    Saturday, June 02, 2012 3:39 PM

All replies

  • Hello:)

    I cannot reproduce your issue, please have a try with my codes:

    namespace LAB5A
    {
        class Program
        {
            static void Main(string[] args)
            {
                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                dt.Columns.Add("Id", typeof(int));
                for (int i = 1; i < 11; i++)
                {
                    dt.Rows.Add(i);
                }
                ds.Tables.Add(dt);
    
                ds.WriteXml("c:\\try.xml", XmlWriteMode.WriteSchema);
                ds.Tables.Clear();
                ds.ReadXml("c:\\try.xml", XmlReadMode.ReadSchema);
    
                //Print out
                foreach (DataTable item in ds.Tables)
                {
                    foreach (DataRow row in item.Rows)
                    {
                        foreach (DataColumn col in item.Columns)
                        {
                            Console.WriteLine(row[col].ToString());
                        }
                    }
                }
            }
        }
    }


       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    Sunday, June 03, 2012 8:18 AM
  • Try adding more columns then they wont show up in the datagridview when you do ReadXml and yes I tried clearing the table.
    Sunday, June 03, 2012 9:13 PM
  • Try adding more columns then they wont show up in the datagridview when you do ReadXml and yes I tried clearing the table.
    ds.ReadXml("c:\\try.xml", XmlReadMode.ReadSchema);
    ds.Tables[0].Columns.Add("AnotherColumn",typeof(string)); //Have a try now


       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    Monday, June 04, 2012 1:06 AM
  • try ReadXML into a table with no columns, In my program the columns are added by the user so they aint already there when ReadXML is run.
    Monday, June 04, 2012 4:12 PM
  • try ReadXML into a table with no columns, In my program the columns are added by the user so they aint already there when ReadXML is run.
    What did you mean?Please show us your full codes……

       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    Tuesday, June 05, 2012 1:10 AM