forodo
پنج شنبه 22 خرداد 1393, 20:27 عصر
سلام
چرا فقط آخرین سطر دیتاگریدویو داخل فایل Xml ذخیره می شه؟
XmlDocument xdoc = new XmlDocument();
string xPath = @"ali.xml";
//گره های لازم را ایجاد می کنیم
XmlDeclaration declaration = xdoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
XmlComment comment = xdoc.CreateComment("This is an XML Generated File");
XmlElement root = xdoc.CreateElement("Persons");
XmlElement person = xdoc.CreateElement("Person");
XmlAttribute name = xdoc.CreateAttribute("name");
XmlElement age = xdoc.CreateElement("Age");
xdoc.AppendChild(declaration);
xdoc.AppendChild(comment);
xdoc.AppendChild(root);
//مقادیر را به گره ها اضافه می کنیم
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
name.Value = dataGridView1.Rows[i].Cells[0].Value.ToString();
age.InnerText = dataGridView1.Rows[i].Cells[1].Value.ToString();
button1.Focus();
//سند را ایجاد می کنیم
root.AppendChild(person);
person.Attributes.Append(name);
person.AppendChild(age);
}
xdoc.Save(xPath);
من داخل دیتاگریدویو اینو می زنم.
1 1
2 2
که سطر آخر فقط ذخیره می شه!
http://up.iranfilm182.com/images/76850542867071181587.png
چرا فقط آخرین سطر دیتاگریدویو داخل فایل Xml ذخیره می شه؟
XmlDocument xdoc = new XmlDocument();
string xPath = @"ali.xml";
//گره های لازم را ایجاد می کنیم
XmlDeclaration declaration = xdoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
XmlComment comment = xdoc.CreateComment("This is an XML Generated File");
XmlElement root = xdoc.CreateElement("Persons");
XmlElement person = xdoc.CreateElement("Person");
XmlAttribute name = xdoc.CreateAttribute("name");
XmlElement age = xdoc.CreateElement("Age");
xdoc.AppendChild(declaration);
xdoc.AppendChild(comment);
xdoc.AppendChild(root);
//مقادیر را به گره ها اضافه می کنیم
for (int i = 0; i < dataGridView1.RowCount - 1; i++)
{
name.Value = dataGridView1.Rows[i].Cells[0].Value.ToString();
age.InnerText = dataGridView1.Rows[i].Cells[1].Value.ToString();
button1.Focus();
//سند را ایجاد می کنیم
root.AppendChild(person);
person.Attributes.Append(name);
person.AppendChild(age);
}
xdoc.Save(xPath);
من داخل دیتاگریدویو اینو می زنم.
1 1
2 2
که سطر آخر فقط ذخیره می شه!
http://up.iranfilm182.com/images/76850542867071181587.png