using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlServerCe;
namespace ExportSDF
{
class Program
{
static void Main(string[] args)
{
SqlCeConnection conn = null;
SqlCeCommand cmd = null;
SqlCeDataReader rdr = null;
try
{
conn = new SqlCeConnection(@"Data Source = C:\Program Files\Microsoft SQL Server Compact Edition\v3.1\SDK\Samples\Northwind.sdf;max database size=256");
conn.Open();
cmd = new SqlCeCommand("SELECT * FROM Customers", conn);
rdr = cmd.ExecuteReader();
System.IO.TextWriter stm = new System.IO.StreamWriter(new System.IO.FileStream(@"C:\customers.csv", System.IO.FileMode.Create), Encoding.Default);
while (rdr.Read())
{
for (int i = 0; i < rdr.FieldCount-2; i++)
{
if (rdr[i] != null)
{
stm.Write(rdr[i].ToString());
stm.Write(";");
}
else
{
stm.Write(";");
}
}
if (rdr[rdr.FieldCount-1] != null)
{
stm.Write(rdr[0].ToString());
}
stm.Write(System.Environment.NewLine);
}
stm.Close();
rdr.Close();
cmd.Dispose();
}
finally
{
// Close the connection when no longer needed
//
conn.Close();
}
}
}
}
这个程序不工作请帮我一个代码或应用程序将所有表一起转换为csv file.i有一些应用程序一次只转换一个表。我不能选择多个表。