导入导出CSV
const string dataPath = @"D:\Users\jin_h\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\";
private static DataTable GetCsvData(string filePath, string fileName) { string connString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + filePath + ";Extensions=asc,csv,tab,txt;"; try { using (var odbcConn = new OdbcConnection(connString)) { odbcConn.Open(); var oleComm = new OdbcCommand(); oleComm.Connection = odbcConn; oleComm.CommandText = "select * from [" + fileName + "#csv]"; var adapter = new OdbcDataAdapter(oleComm); var ds = new DataSet(); adapter.Fill(ds, fileName); return ds.Tables[0]; } } catch (Exception ex) { throw ex; } } private static string ExportCSV(IEnumerable<ErrorData> errorDate) { var sbBuilder = new StringBuilder(); string[] title = { "ScenciSpotID", "DistrictNamePath", "GeographicRegionKeyword", "NoMatchField" }; foreach (var t in title) { sbBuilder.Append(t + ","); } sbBuilder.Append("\n"); foreach (var field in errorDate) { sbBuilder.Append(field.ScenciSpotID + ","); sbBuilder.Append(field.DistrictNamePath + ","); sbBuilder.Append(field.GeographicRegionKeyword + ","); sbBuilder.Append(field.NoMatchField + ","); sbBuilder.Append("\n"); } return sbBuilder.ToString(); }