using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Collections;
using System.Xml;
namespace ADO
{
class Program
{
static ArrayList alist = new ArrayList();
static string dbname = "master";//数据库名称
static void Main(string[] args)
{
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123456;database="+dbname+"");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select name from sysobjects where type='u'";//数据库中用户表
cmd.Connection = con;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
alist.Add(dr[0]);//存放表名
Console.WriteLine(alist[alist.Count-1]);//显示表名
}
con.Close();
split();
for (int i = 0; i < alist.Count;i++)
{
printAll(alist[i]);
split();
}
Console.Read();
}
static void split()
{
for (int i = 0; i <= 20; i++)
{
if (i == 8)
{
Console.Write("我是调皮的分割线");
}
Console.Write("-");
}
Console.WriteLine();
}
static void printAll(object table)//将表中的数据以XML形式显示出来
{
SqlConnection conn = new SqlConnection("server=.;database="+dbname+";uid=sa;pwd=123456");
SqlCommand cmdd = new SqlCommand("select top 10 * from "+table+" for xml auto", conn);
//cmdd.Parameters.AddWithValue("@table",table);
conn.Open();
XmlReader xr = cmdd.ExecuteXmlReader();
while(xr.Read())
{
Console.WriteLine(xr.ReadOuterXml());
}
conn.Close();
}
}
}