源码下载:http://dl2.csdn.net/down4/20070910/10202340430.rar
说明:首先建立WindowsApplication2,然后在E盘建立wangleiaaaaa文件夹.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=wl_xx;User Id=sa;Pwd=kelu");
con.Open();
try
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from persen", con);
da.Fill(ds, "persen");
SqlDataAdapter da1 = new SqlDataAdapter("select * from persenType", con);
da1.Fill(ds, "persenType");
DataRelation dr = ds.Relations.Add("persenType", ds.Tables["persenType"].Columns["PId"], ds.Tables["persen"].Columns["PId"]);
dr.Nested = true;
ds.WriteXml(@"e:/wangleiaaaaa/bbb.xml");
DialogResult result= MessageBox.Show("成功写入","小提示",MessageBoxButtons.OK);
if (result ==DialogResult.OK)
{
Application.Exit();
}
}
catch (Exception ex)
{
MessageBox.Show("写入错误,错误原因:" + ex.ToString());
}
finally
{
con.Close();
}
}
}
}