C#查询数据库把结果输出到XML的例子
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//sqlserver身份验证
//string sqlconn = "server=(local);database=keede1228;user id=sa;password=123;";
//windows身份验证
string sqlconn = "server=(local);database=keede1228;integrated security=SSPI;";
string select = "dirr4";
SqlConnection conn = new SqlConnection(sqlconn);
Console.WriteLine("33");
conn.Open();
Console.WriteLine("11");
//SqlCommand cmd = new SqlCommand(select, conn);
//SqlDataReader reader = cmd.ExecuteReader();
//while (reader.Read())
//{
// Console.WriteLine("cityid:{0} city:{1} area:{2}", reader[0], reader[1], reader[2]);
//}
SqlDataAdapter da = new SqlDataAdapter(select, conn);
DataSet ds = new DataSet();
da.Fill(ds, "custo");
foreach (DataRow row in ds.Tables["custo"].Rows)
Console.WriteLine("'{0}'from {1}", row[0], row[1]);
ds.WriteXml("write.xml", XmlWriteMode.WriteSchema);
conn.Close();
Console.WriteLine("22");
Console.ReadKey();
}
}
}
DataSet类太强大了!
相关文档:
买了战争机器2,写完教程准备杀到睡觉,现在先做第一步,写教程。AIR的文件操作不难,看完教程应该可以满足你对文件的所有基本操作。这篇教程主要以实际操作中遇到的情况来讲解
我们想想文件操作都会有什么内容,无非是创建,修改,删除,移动,拷贝。在这个过程中我们会涉及到一些周边的操作,比如文件夹,文件选择器,文 ......
有时候我门需要把EXCEL表格中的数据转换成XML格式 这需要用到JXL(分析EXCEL)包和JDOM包(构成XML)
import java.io.*;
import jxl.*;
import org.jdom.Element;
import org.jdom.Document;
import org.jdom.output.XMLOutputter;
/**
*
* @author guo
*/
public class EtoX {
  ......
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" viewSourceURL="srcview/index.html">
<mx:S ......
作者:wuhua
空间:htt://wuhua.3geye.net
转载请保留上面的信息(请尊重知识产品)谢谢
相信大家都用过Kxml的东西了,不过个人感觉kxml还是大了些。现在介绍一个比kxml跟简介的xml的类。对于一些小项目,或者对xml解释要求不是很高的项目来说却是个不错的选择。
下面看看那代码与Demo吧。
Java代码
package o ......