//从数据库生成DataSet
        public DataSet CreateDataSet()
        {
            
//创建到Sql server数据库的连接
            SqlConnection conn = new SqlConnection("server=.;database=test;uid=sa;pwd=sa");
            SqlDataAdapter sdr 
= new SqlDataAdapter();
            
//创建关于table1表的数据集
            sdr.SelectCommand = new SqlCommand("select * from table1",conn);
            
//声明DataSet
            DataSet ds = new DataSet();
            sdr.Fill(ds,
"XMLtest");
            
//返回DataSet数据集
            return ds;
        }

        
//创建写入到 XML 文件
        private void XMLfile()
        {
            
//要写入文件的路径
            string filepath = Server.MapPath("test.xml");
            CreateDataSet().WriteXml(filepath);
        }

//最后在按钮事件中的,指定XMLfile方法
     this.XMLfile();

相关文章:

  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-11-27
  • 2021-07-14
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案