Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have DataGridView in a form which is loaded from a XML file when the form is loaded. This XML file is updated every time a new row is added to the datagridview.
Initially it was working fine but now it is showing the following error :
"Child list for field <tablename> cannot be created." where <tablename> is the name of the table.

This is what i am doing :

C#
DataSet dataSet = new DataSet();
dataSet.ReadXml(@"D:\HostAdded.xml");
DataRow row = dataSet.Tables[0].NewRow();
row.ItemArray = new object[] { txthostname.Text, ipAddr, txtusername.Text, txtpassword.Text };
dataSet.Tables[0].Rows.Add(row);
dataGridView1.DataSource = dataSet;
dataGridView1.DefaultCellStyle.ForeColor = Color.Red;
dataGridView1.AutoGenerateColumns = false;
txtLog.AppendText(Environment.NewLine + "\nRow added successfully");
createXML();


createXML()
C#
DataTable dt = new DataTable();
            foreach (DataGridViewColumn col in dataGridView1.Columns)
            {
                dt.Columns.Add(col.HeaderText);
            }
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                DataRow dRow = dt.NewRow();
                foreach (DataGridViewCell cell in row.Cells)
                {
                    dRow[cell.ColumnIndex] = cell.Value;
                }
                dt.Rows.Add(dRow);
            }
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            ds.WriteXml(@"D:/HostAdded.xml");


Please help!!!
Thanks :)
Posted

1 solution

set DataMember property as below
C#
dataGridView1.DataSource = dataSet;
dataGridView1.DataMember = "HostAdded";
 
Share this answer
 
Comments
sovit agarwal 28-May-14 5:44am    
Thanks....
Let me check if its working fine...
sovit agarwal 28-May-14 5:53am    
sorry bro,...but it ain't working
sovit agarwal 28-May-14 5:53am    
same error.....the previous vale that was written to the file is also deleted..
DamithSL 28-May-14 8:22am    
in which line you get this error?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900