跟导入代码没有什么区别?你其实应该多想下!
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (FileStream fs = File.OpenWrite(saveFileDialog1.FileName))
{
using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312")))
{
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\dd.mdf';Integrated Security=True;User Instance=True"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from T_Persons";
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
string name = sdr.GetString(sdr.GetOrdinal("Name"));
int age = sdr.GetInt32(sdr.GetOrdinal("Age"));
string line =name+"|"+age;
sw.WriteLine(line);
sw.Flush();
}