博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用数据集和XML
阅读量:6936 次
发布时间:2019-06-27

本文共 1228 字,大约阅读时间需要 4 分钟。

可以使用ReadXml()和WriteXml()方法分别读取数据集中的数据(和模式),写入XML文件。

实例:将数据从数据集写到XML文件中

View Code
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data;using System.Data.SqlClient;namespace WriteXML{    class Program    {        static void Main(string[] args)        {            string connString = @"            server =.;            integrated security =true;            database =northwind";            string qry = @"                select productname,unitprice                from products";            SqlConnection conn = new SqlConnection(connString);            try            {                SqlDataAdapter da = new SqlDataAdapter();                da.SelectCommand = new SqlCommand(qry, conn);                conn.Open();                DataSet ds = new DataSet();                da.Fill(ds, "products");                ds.WriteXml(@"c:\\myxml.xml");                Console.WriteLine("The file is Created");            }            catch (Exception e)            {                Console.WriteLine("Error: " + e);            }            finally            {                conn.Close();            }        }    }}

给XML文件提供完整的路径,把它放在解决方案目录中,如果只提供文件名,它就会放在WriteXML项目目录的bin\Release子目录下。

转载地址:http://ctpjl.baihongyu.com/

你可能感兴趣的文章
Ajax与Comet
查看>>
【转载】大连商品交易所-套利交易相关问题
查看>>
vue: axios
查看>>
android之布局
查看>>
(16)让你的网站在移动设备上同样精彩!
查看>>
NSStream文件流
查看>>
C/C++知识点清单02-上
查看>>
第一次上班吃便当
查看>>
jquery返回顶部-ie6配合css表达式。
查看>>
HDU——1267 下沙的沙子有几粒?
查看>>
pandas使用lambda判断元素是否为空或者None
查看>>
MapReduce Shuffle优化方向
查看>>
将博客搬至CSDN
查看>>
xcode快捷键
查看>>
MyBatis
查看>>
仿射变换
查看>>
iOS应用架构谈part3 网络层设计方案
查看>>
react组件生命周期
查看>>
IOS开发之自定义UITabBarController
查看>>
Android 混合式开发AppCan介绍
查看>>