如何级联更新XML文件 [英] How to cascade update XML file

查看:79
本文介绍了如何级联更新XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c#的新手,我正在寻找xml文件的级联更新

因为我有2个课程首先是课程,第二个是教练



我尝试过:



//在xml文件中插入课程类属性



private void button1_Click(对象发件人,EventArgs e)



{

试试

{

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);

}

}



//在xml文件中插入讲师类属性



private void button2_Click_1(object sender,EventArgs e)

{

try

{

instructor inst = new讲师();

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);

}



}

解决方案

在用于保存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[^]


这篇关于如何级联更新XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆