且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何级联更新XML文件

更新时间:2023-02-03 08:16:23

在用于保存XML的所有.NET FCL方法中在一个文件中,你一次写下整个文件,所以不需要任何更新,cascade或者没有。



-SA


看一下可以链接在一起的 BindingSources

这是一个很好的CodeProject上的文章展示了它是如何工作的:

详细数据绑定教程 [ ^

i am a newbie in c# and i am searching for cascade update from xml files
as i have 2 classes first is course and the second is instructor

What I have tried:

// inserts course class attributes in xml file

private void button1_Click(object sender, EventArgs e)

{
try
{
course cor = new course();
cor.course_code = int.Parse(textBox1.Text);
cor.totalnum = int.Parse(textBox2.Text);
cor.name = textBox3.Text;
cor.coursecat = comboBox1.Text;
savexml.SaveData(cor, "data.xml");

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

// inserts instructor class attributes in xml file

private void button2_Click_1(object sender, EventArgs e)
{
try
{
instructor inst = new instructor();
inst.instructor_id = int.Parse(textBox4.Text);
inst.NAME = textBox5.Text;
inst.phone_num = textBox6.Text;
inst.ADDRESS = textBox7.Text;
inst.Email = textBox8.Text;
savexml.SaveData(inst, "data.xml");
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}

}

In all .NET FCL methods used to save XML in a file, you write the whole file at once, so there is no a need in any updates, "cascade" or not.

—SA


Take a look at BindingSources which can be chained together.
Here is an excellent article on CodeProject that shows how it works:
A Detailed Data Binding Tutorial[^]