我想是導(dǎo)出數(shù)據(jù)表到的.csv文件。這是我嘗試過的,但花費的時間太長:string strFilePath= @"C:\myCSVfile.csv";——public void CreateCSVFile(DataTable dtDataTablesList, string strFilePath){ // Create the CSV file to which grid data will be exported. StreamWriter sw = new StreamWriter(strFilePath, false); //First we will write the headers. int iColCount = dtDataTablesList.Columns.Count; for (int i = 0; i < iColCount; i++) { sw.Write(dtDataTablesList.Columns[i]); if (i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); // Now write all the rows. foreach (DataRow dr in dtDataTablesList.Rows) { for (int i = 0; i < iColCount; i++) { if (!Convert.IsDBNull(dr[i])) { sw.Write(dr[i].ToString()); } if (i < iColCount - 1) { sw.Write(","); } } sw.Write(sw.NewLine); } sw.Close();}有沒有其他方法可以更快地做到這一點?預(yù)先感謝您的任何建議。
1 回答

揚帆大魚
TA貢獻1799條經(jīng)驗 獲得超9個贊
現(xiàn)在速度更快了,這就是我所做的:
我計算了處理器的數(shù)量
為每個人創(chuàng)建一個線程
在線程上劃分行
將每個導(dǎo)出到自己的文件
最后合并文件
添加一個不錯的進度顯示
- 1 回答
- 0 關(guān)注
- 171 瀏覽
添加回答
舉報
0/150
提交
取消