本文介绍了如何级联更新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);

}



}

解决方案



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

}

解决方案



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

10-15 05:29