• 通过DataTable向XML添加数据


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace DataTabelTestInXml
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    public static DataTable dt = new DataTable();
    private void button1_Click(object sender, EventArgs e)
    {
    dt.TableName
    = "Tabel1";
    dt.Columns.Add(
    "数量", typeof(int));
    dt.Columns.Add(
    "频率", typeof(int));
    dt.Columns.Add(
    "自动关闭延迟", typeof(int));
    dt.Columns.Add(
    "Url", typeof(string));

    DataColumn[] clos
    = new DataColumn[1];
    clos[
    0] = dt.Columns["Url"];
    dt.PrimaryKey
    = clos;

    DataRow dr;
    dr
    = dt.NewRow();
    dr[
    "数量"] = 100;
    dr[
    "频率"] = 100;
    dr[
    "自动关闭延迟"] = 100;
    dr[
    "Url"] = "http://www.baidu.com/";
    dt.Rows.Add(dr);

    dr
    = dt.NewRow();
    dr[
    "数量"] = 500;
    dr[
    "频率"] = 500;
    dr[
    "自动关闭延迟"] = 500;
    dr[
    "Url"] = "sdfasdfasd";
    dt.Rows.Add(dr);
    /*
    <?xml version="1.0" standalone="yes"?>
    <DocumentElement>
    <Tabel1>
    <数量>100</数量>
    <频率>100</频率>
    <自动关闭延迟>100</自动关闭延迟>
    <Url>
    http://www.baidu.com/</Url>
    </Tabel1>
    <Tabel1>
    <数量>500</数量>
    <频率>500</频率>
    <自动关闭延迟>500</自动关闭延迟>
    <Url>sdfasdfasd</Url>
    </Tabel1>
    </DocumentElement>

    */



    dt.WriteXml(
    @"D:\1.XML");
    }
    }
    }
  • 相关阅读:
    Mybatis应用
    MyBatis
    jQuery中.bind() .live() .delegate() .on()的区别
    SpringMVC (八)SpringMVC返回值类型
    SpringMVC(七)参数的自动装配和路径变量
    SpringMVC (六)注解式开发
    SpringMVC (五)视图解析器
    SpringMVC (四)MultiActionController
    SourceTree的使用
    Idea中使用git
  • 原文地址:https://www.cnblogs.com/beeone/p/2012977.html
Copyright © 2020-2023  润新知