2016-11-25 21 views
0
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有任何應用程序某些應用程序一次只能轉換一個表格,我無法選擇多個表格。如何從SDF文件中的所有錶轉換一起csv文件在C#或轉換

回答

0

從我所看到的,你得到了here的代碼。 您能清楚什麼不起作用嗎?你試過什麼了? 在我看來,你只複製了代碼,但沒有更改數據源,這顯然不適合你。

謝謝。

+0

我修改了數據源。問題是它沒有采取表頭和列[LumId] VARBINARY(16)NOT NULL,顯示爲System.Byte []; –