vb.net如何读取XML的数据到控件和读取对应的数据到控件
XML内容为<?xmlversion='1.0'encoding='GB2312'?><Set><a1>969</a1><a2>455</a2><a3>356</a3><...
XML内容为
<?xml version='1.0' encoding='GB2312'?>
<Set>
<a1>969</a1>
<a2>455</a2>
<a3>356</a3>
<a4>646</a4>
</Set>
如果要把a1到a4的数据放进textbox1.text到textbox4.text,代码应该怎么写?
=============================================================
txt内容为
a1=969
a2=455
a3=356
a4=646
如果要读取txt把a1到a4的数据放进textbox1.text到textbox4.text,代码应该怎么写? 展开
<?xml version='1.0' encoding='GB2312'?>
<Set>
<a1>969</a1>
<a2>455</a2>
<a3>356</a3>
<a4>646</a4>
</Set>
如果要把a1到a4的数据放进textbox1.text到textbox4.text,代码应该怎么写?
=============================================================
txt内容为
a1=969
a2=455
a3=356
a4=646
如果要读取txt把a1到a4的数据放进textbox1.text到textbox4.text,代码应该怎么写? 展开
1个回答
展开全部
private void button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml("D:\\1.xml");
foreach (DataRow row in ds.Tables[0].Rows)
{
string a1 = row[0].ToString();
string a2 = row[1].ToString();
string a3 = row[2].ToString();
string a4 = row[3].ToString();
MessageBox.Show(a1);
MessageBox.Show(a2);
MessageBox.Show(a3);
MessageBox.Show(a4);
}
}
更多追问追答
追问
能不能根据
969
455
356
646
的名称来读
追答
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim ds As New DataSet
ds.ReadXml("D:\1.xml")
Dim r As DataRow = ds.Tables(0)(0)
Dim a1 As String = r("a1")
Dim a2 As String = r("a2")
Dim a3 As String = r("a3")
Dim a4 As String = r("a4")
MsgBox(String.Format("a1={0} a1={1} a3={2} a4={3}", a1, a2, a3, a4))
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询