• 简单读写xml


    private void button1_Click(object sender, EventArgs e)
    {
    XDocument dow = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"), new XElement("person", new XElement("age",12345)));
    dow.Save(Application.StartupPath + "\\my.xml");
    MessageBox.Show("创建成功!");
    }

    private void button2_Click(object sender, EventArgs e)
    {
    string s = Application.StartupPath + "\\myy.xml";
    XElement xe = XElement.Load(s);
    IEnumerable<XElement> elements = from pinfo in xe.Elements("appset")
    where pinfo.Attribute("Id").Value == "lisenerror"
    select pinfo;
    string conn = null ;
    foreach(XElement elem in elements)
    {
    conn= elem.Element("strconn").Value;
    }

    SqlConnection conns = new SqlConnection(conn);
    SqlCommand cmd = new SqlCommand("select * from tbBtoB", conns);
    SqlDataAdapter adpt = new SqlDataAdapter();
    adpt.SelectCommand = cmd;
    DataSet ds = new DataSet();

    conns.Open();
    MessageBox.Show("open successs");
    adpt.Fill(ds, "2");
    MessageBox.Show(ds.Tables["2"].Rows.Count.ToString());
    conns.Close();

    }

    -----------------以下是上面那个读取xml的内容---------------------

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <Settings>
    <Appset Id="lisenError">
    <strconn>server=qiaopc;database=JLDu;user id=sa;password=234561</strconn>
    </Appset>
    </Settings>

  • 相关阅读:
    (转载)构建public APIs与CORS
    SpringMVC 参数注入
    java删除文件夹
    idea 自动提示生成 serialVersionUID
    JSP自定义tag
    gradle中使用嵌入式(embedded) tomcat, debug 启动
    spring in action 4th --- quick start
    Date, TimeZone, MongoDB, java中date的时区问题
    spring boot 添加拦截器
    HTTP status code
  • 原文地址:https://www.cnblogs.com/zhuzhuxia/p/2735339.html
Copyright © 2020-2023  润新知