我需要将大DataTable
(> 50 lacs( 5M ) DataRows ) 导出到.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();
}
请让我知道任何其他快速完成的方法。